From d85d4fea5decbf22008a58a8a79306f91a13a455 Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Wed, 2 Apr 2014 12:46:57 +0530 Subject: [PATCH 01/37] Added the new Running Scripts widget --- interface/interface_en.ts | 67 +++- interface/resources/images/kill-script.svg | 7 + interface/resources/images/reload.svg | 24 ++ interface/resources/images/stop.svg | 7 + interface/resources/resources.qrc | 3 + interface/src/Application.cpp | 320 ++++++++++--------- interface/src/Application.h | 39 ++- interface/src/Menu.cpp | 121 +++---- interface/src/Menu.h | 10 +- interface/src/ui/RunningScriptsWidget.cpp | 203 ++++++++++++ interface/src/ui/RunningScriptsWidget.h | 46 +++ interface/ui/runningScriptsWidget.ui | 248 ++++++++++++++ libraries/script-engine/src/ScriptEngine.cpp | 131 +++----- libraries/script-engine/src/ScriptEngine.h | 33 +- 14 files changed, 920 insertions(+), 339 deletions(-) create mode 100644 interface/resources/images/kill-script.svg create mode 100644 interface/resources/images/reload.svg create mode 100644 interface/resources/images/stop.svg create mode 100644 interface/src/ui/RunningScriptsWidget.cpp create mode 100644 interface/src/ui/RunningScriptsWidget.h create mode 100644 interface/ui/runningScriptsWidget.ui diff --git a/interface/interface_en.ts b/interface/interface_en.ts index 7c5d1ecbcf..cbe0ac1f25 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 @@ -158,4 +158,55 @@ + + RunningScriptsWidget + + + + Form + + + + + + <html><head/><body><p><span style=" font-size:18pt;">Running Scripts</span></p></body></html> + + + + + + <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> + + + + + + Reload All + + + + + + Stop All + + + + + + <html><head/><body><p><span style=" font-weight:600;">Recently loaded</span></p></body></html> + + + + + + (click a script or use the 1-9 keys to load and run it) + + + + + + There are no scripts currently running. + + + diff --git a/interface/resources/images/kill-script.svg b/interface/resources/images/kill-script.svg new file mode 100644 index 0000000000..d98fc4555a --- /dev/null +++ b/interface/resources/images/kill-script.svg @@ -0,0 +1,7 @@ + + + + + + diff --git a/interface/resources/images/reload.svg b/interface/resources/images/reload.svg new file mode 100644 index 0000000000..a596f03301 --- /dev/null +++ b/interface/resources/images/reload.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + diff --git a/interface/resources/images/stop.svg b/interface/resources/images/stop.svg new file mode 100644 index 0000000000..ea22bb592a --- /dev/null +++ b/interface/resources/images/stop.svg @@ -0,0 +1,7 @@ + + + + + + diff --git a/interface/resources/resources.qrc b/interface/resources/resources.qrc index 372fa8b1d4..35c0e40270 100644 --- a/interface/resources/resources.qrc +++ b/interface/resources/resources.qrc @@ -1,5 +1,8 @@ images/close.svg + images/kill-script.svg + images/reload.svg + images/stop.svg diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d91e686844..386e81aa0b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include #include @@ -118,7 +118,7 @@ void messageHandler(QtMsgType type, const QMessageLogContext& context, const QSt if (message.size() > 0) { QString dateString = QDateTime::currentDateTime().toTimeSpec(Qt::LocalTime).toString(Qt::ISODate); QString formattedMessage = QString("[%1] %2\n").arg(dateString).arg(message); - + fprintf(stdout, "%s", qPrintable(formattedMessage)); Application::getInstance()->getLogger()->addMessage(qPrintable(formattedMessage)); } @@ -174,23 +174,23 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); - + // set the associated application properties applicationInfo.beginGroup("INFO"); - + qDebug() << "[VERSION] Build sequence: " << qPrintable(applicationVersion()); - + setApplicationName(applicationInfo.value("name").toString()); setApplicationVersion(BUILD_VERSION); setOrganizationName(applicationInfo.value("organizationName").toString()); setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); - + QSettings::setDefaultFormat(QSettings::IniFormat); - + _myAvatar = _avatarManager.getMyAvatar(); _applicationStartupTime = startup_time; - + QFontDatabase::addApplicationFont(Application::resourcesPath() + "styles/Inconsolata.otf"); _window->setWindowTitle("Interface"); @@ -205,19 +205,19 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : if (portStr) { listenPort = atoi(portStr); } - + // start the nodeThread so its event loop is running _nodeThread->start(); - + // make sure the node thread is given highest priority _nodeThread->setPriority(QThread::TimeCriticalPriority); - + // put the NodeList and datagram processing on the node thread NodeList* nodeList = NodeList::createInstance(NodeType::Agent, listenPort); - + nodeList->moveToThread(_nodeThread); _datagramProcessor.moveToThread(_nodeThread); - + // connect the DataProcessor processDatagrams slot to the QUDPSocket readyRead() signal connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), &_datagramProcessor, SLOT(processDatagrams())); @@ -239,20 +239,20 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer))); connect(nodeList, &NodeList::uuidChanged, this, &Application::updateWindowTitle); connect(nodeList, &NodeList::limitOfSilentDomainCheckInsReached, nodeList, &NodeList::reset); - + // connect to appropriate slots on AccountManager AccountManager& accountManager = AccountManager::getInstance(); connect(&accountManager, &AccountManager::authRequired, Menu::getInstance(), &Menu::loginForCurrentDomain); connect(&accountManager, &AccountManager::usernameChanged, this, &Application::updateWindowTitle); - + // set the account manager's root URL and trigger a login request if we don't have the access token accountManager.setAuthURL(DEFAULT_NODE_AUTH_URL); - + // once the event loop has started, check and signal for an access token QMetaObject::invokeMethod(&accountManager, "checkAndSignalForAccessToken", Qt::QueuedConnection); _settings = new QSettings(this); - + // Check to see if the user passed in a command line option for loading a local // Voxel File. _voxelsFilename = getCmdOption(argc, constArgv, "-i"); @@ -266,7 +266,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : nodeList->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer << NodeType::AvatarMixer << NodeType::VoxelServer << NodeType::ParticleServer << NodeType::MetavoxelServer); - + // connect to the packet sent signal of the _voxelEditSender and the _particleEditSender connect(&_voxelEditSender, &VoxelEditPacketSender::packetSent, this, &Application::packetSent); connect(&_particleEditSender, &ParticleEditPacketSender::packetSent, this, &Application::packetSent); @@ -276,7 +276,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : connect(silentNodeTimer, SIGNAL(timeout()), nodeList, SLOT(removeSilentNodes())); silentNodeTimer->moveToThread(_nodeThread); silentNodeTimer->start(NODE_SILENCE_THRESHOLD_USECS / 1000); - + // send the identity packet for our avatar each second to our avatar mixer QTimer* identityPacketTimer = new QTimer(); connect(identityPacketTimer, &QTimer::timeout, _myAvatar, &MyAvatar::sendIdentityPacket); @@ -324,14 +324,18 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : // Set the sixense filtering _sixenseManager.setFilter(Menu::getInstance()->isOptionChecked(MenuOption::FilterSixense)); - + checkVersion(); - + _overlays.init(_glWidget); // do this before scripts load - + LocalVoxelsList::getInstance()->addPersistantTree(DOMAIN_TREE_NAME, _voxels.getTree()); LocalVoxelsList::getInstance()->addPersistantTree(CLIPBOARD_TREE_NAME, &_clipboard); + _window->addDockWidget(Qt::NoDockWidgetArea, _runningScriptsWidget = new RunningScriptsWidget()); + _runningScriptsWidget->setRunningScripts(getRunningScripts()); + connect(_runningScriptsWidget, &RunningScriptsWidget::stopScriptName, this, &Application::stopScript); + // check first run... QVariant firstRunValue = _settings->value("firstRun",QVariant(true)); if (firstRunValue.isValid() && firstRunValue.toBool()) { @@ -339,7 +343,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : // clear the scripts, and set out script to our default scripts clearScriptsBeforeRunning(); loadScript("http://public.highfidelity.io/scripts/defaultScripts.js"); - + _settings->setValue("firstRun",QVariant(false)); } else { // do this as late as possible so that all required subsystems are inialized @@ -350,31 +354,31 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : Application::~Application() { qInstallMessageHandler(NULL); - + // make sure we don't call the idle timer any more delete idleTimer; - + Menu::getInstance()->saveSettings(); _rearMirrorTools->saveSettings(_settings); - + _sharedVoxelSystem.changeTree(new VoxelTree); if (_voxelImporter) { _voxelImporter->saveSettings(_settings); delete _voxelImporter; } _settings->sync(); - + // let the avatar mixer know we're out MyAvatar::sendKillAvatar(); - + // ask the datagram processing thread to quit and wait until it is done _nodeThread->quit(); _nodeThread->wait(); - + // ask the audio thread to quit and wait until it is done _audio.thread()->quit(); _audio.thread()->wait(); - + _voxelProcessor.terminate(); _voxelHideShowThread.terminate(); _voxelEditSender.terminate(); @@ -387,9 +391,9 @@ Application::~Application() { Menu::getInstance()->deleteLater(); _myAvatar = NULL; - + delete _glWidget; - + AccountManager::getInstance().destroy(); } @@ -581,7 +585,7 @@ void Application::paintGL() { if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { renderRearViewMirror(_mirrorViewRect); - + } else if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { _rearMirrorTools->render(true); } @@ -654,10 +658,10 @@ void Application::controlledBroadcastToNodes(const QByteArray& packet, const Nod if (type == NodeType::VoxelServer && !Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) { continue; } - + // Perform the broadcast for one type int nReceivingNodes = NodeList::getInstance()->broadcastToNodes(packet, NodeSet() << type); - + // Feed number of bytes to corresponding channel of the bandwidth meter, if any (done otherwise) BandwidthMeter::ChannelIndex channel; switch (type) { @@ -676,7 +680,7 @@ void Application::controlledBroadcastToNodes(const QByteArray& packet, const Nod } bool Application::event(QEvent* event) { - + // handle custom URL if (event->type() == QEvent::FileOpen) { QFileOpenEvent* fileEvent = static_cast(event); @@ -687,11 +691,11 @@ bool Application::event(QEvent* event) { if (urlParts.count() > 1) { // if url has 2 or more parts, the first one is domain name Menu::getInstance()->goToDomain(urlParts[0]); - + // location coordinates Menu::getInstance()->goToDestination(urlParts[1]); if (urlParts.count() > 2) { - + // location orientation Menu::getInstance()->goToOrientation(urlParts[2]); } @@ -701,7 +705,7 @@ bool Application::event(QEvent* event) { Menu::getInstance()->goToDestination(urlParts[0]); } } - + return false; } return QApplication::event(event); @@ -712,7 +716,7 @@ void Application::keyPressEvent(QKeyEvent* event) { _keysPressed.insert(event->key()); _controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts - + // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isKeyCaptured(event)) { return; @@ -1071,7 +1075,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event) { checkBandwidthMeterClick(); if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { checkStatsClick(); - } + } } } } @@ -1120,7 +1124,7 @@ void Application::touchBeginEvent(QTouchEvent* event) { if (_controllerScriptingInterface.isTouchCaptured()) { return; } - + // put any application specific touch behavior below here.. _lastTouchAvgX = _touchAvgX; _lastTouchAvgY = _touchAvgY; @@ -1163,13 +1167,13 @@ void Application::dropEvent(QDropEvent *event) { break; } } - + SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath); if (snapshotData) { if (!snapshotData->getDomain().isEmpty()) { Menu::getInstance()->goToDomain(snapshotData->getDomain()); } - + _myAvatar->setPosition(snapshotData->getLocation()); _myAvatar->setOrientation(snapshotData->getOrientation()); } else { @@ -1197,19 +1201,19 @@ void Application::timer() { } _fps = (float)_frameCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); - + _packetsPerSecond = (float) _datagramProcessor.getPacketCount() / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); _bytesPerSecond = (float) _datagramProcessor.getByteCount() / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); _frameCount = 0; - + _datagramProcessor.resetCounters(); gettimeofday(&_timerStart, NULL); // ask the node list to check in with the domain server NodeList::getInstance()->sendDomainServerCheckIn(); - - + + } void Application::idle() { @@ -1246,11 +1250,11 @@ void Application::idle() { _idleLoopMeasuredJitter = _idleLoopStdev.getStDev(); _idleLoopStdev.reset(); } - + if (Menu::getInstance()->isOptionChecked(MenuOption::BuckyBalls)) { _buckyBalls.simulate(timeSinceLastUpdate / 1000.f, Application::getInstance()->getAvatar()->getHandData()); } - + // After finishing all of the above work, restart the idle timer, allowing 2ms to process events. idleTimer->start(2); } @@ -1382,7 +1386,7 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) { tr("Sparse Voxel Octree Files (*.svo)")); QByteArray fileNameAscii = fileNameString.toLocal8Bit(); const char* fileName = fileNameAscii.data(); - + VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); if (selectedNode) { VoxelTree exportTree; @@ -1396,12 +1400,12 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) { void Application::importVoxels() { _importSucceded = false; - + if (!_voxelImporter) { _voxelImporter = new VoxelImporter(_window); _voxelImporter->loadSettings(_settings); } - + if (!_voxelImporter->exec()) { qDebug() << "[DEBUG] Import succeeded." << endl; _importSucceded = true; @@ -1415,7 +1419,7 @@ void Application::importVoxels() { // restore the main window's active state _window->activateWindow(); - + emit importDone(); } @@ -1471,7 +1475,7 @@ void Application::pasteVoxels(const VoxelDetail& sourceVoxel) { } pasteVoxelsToOctalCode(octalCodeDestination); - + if (calculatedOctCode) { delete[] calculatedOctCode; } @@ -1508,9 +1512,9 @@ void Application::init() { // Cleanup of the original shared tree _sharedVoxelSystem.init(); - + _voxelImporter = new VoxelImporter(_window); - + _environment.init(); _glowEffect.init(); @@ -1552,11 +1556,11 @@ void Application::init() { _audio.setJitterBufferSamples(Menu::getInstance()->getAudioJitterBufferSamples()); } qDebug("Loaded settings"); - + // initialize Visage and Faceshift after loading the menu settings _faceshift.init(); _visage.init(); - + // fire off an immediate domain-server check in now that settings are loaded NodeList::getInstance()->sendDomainServerCheckIn(); @@ -1575,20 +1579,20 @@ void Application::init() { _particleCollisionSystem.init(&_particleEditSender, _particles.getTree(), _voxels.getTree(), &_audio, &_avatarManager); // connect the _particleCollisionSystem to our script engine's ParticleScriptingInterface - connect(&_particleCollisionSystem, + connect(&_particleCollisionSystem, SIGNAL(particleCollisionWithVoxel(const ParticleID&, const VoxelDetail&, const glm::vec3&)), - ScriptEngine::getParticlesScriptingInterface(), + ScriptEngine::getParticlesScriptingInterface(), SLOT(forwardParticleCollisionWithVoxel(const ParticleID&, const VoxelDetail&, const glm::vec3&))); - connect(&_particleCollisionSystem, + connect(&_particleCollisionSystem, SIGNAL(particleCollisionWithParticle(const ParticleID&, const ParticleID&, const glm::vec3&)), - ScriptEngine::getParticlesScriptingInterface(), + ScriptEngine::getParticlesScriptingInterface(), SLOT(forwardParticleCollisionWithParticle(const ParticleID&, const ParticleID&, const glm::vec3&))); - + _audio.init(_glWidget); _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings); - + connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView())); connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView())); connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView())); @@ -1711,7 +1715,7 @@ void Application::updateMyAvatarLookAtPosition() { float distance = TREE_SCALE; if (_myAvatar->getLookAtTargetAvatar() && _myAvatar != _myAvatar->getLookAtTargetAvatar()) { distance = glm::distance(_mouseRayOrigin, - static_cast(_myAvatar->getLookAtTargetAvatar())->getHead()->calculateAverageEyePosition()); + static_cast(_myAvatar->getLookAtTargetAvatar())->getHead()->calculateAverageEyePosition()); } const float FIXED_MIN_EYE_DISTANCE = 0.3f; float minEyeDistance = FIXED_MIN_EYE_DISTANCE + (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON ? 0.0f : @@ -1724,7 +1728,7 @@ void Application::updateMyAvatarLookAtPosition() { eyePitch = _faceshift.getEstimatedEyePitch(); eyeYaw = _faceshift.getEstimatedEyeYaw(); trackerActive = true; - + } else if (_visage.isActive()) { eyePitch = _visage.getEstimatedEyePitch(); eyeYaw = _visage.getEstimatedEyeYaw(); @@ -1907,9 +1911,9 @@ void Application::update(float deltaTime) { _particles.update(); // update the particles... _particleCollisionSystem.update(); // collide the particles... - + _overlays.update(deltaTime); - + // let external parties know we're updating emit simulating(deltaTime); } @@ -1933,7 +1937,7 @@ void Application::updateMyAvatar(float deltaTime) { // actually need to calculate the view frustum planes to send these details // to the server. loadViewFrustum(_myCamera, _viewFrustum); - + // Update my voxel servers with my current voxel query... quint64 now = usecTimestampNow(); quint64 sinceLastQuery = now - _lastQueriedTime; @@ -2209,7 +2213,7 @@ void Application::updateShadowMap() { } center = inverseRotation * center; glm::vec3 minima(center.x - radius, center.y - radius, center.z - radius); - glm::vec3 maxima(center.x + radius, center.y + radius, center.z + radius); + glm::vec3 maxima(center.x + radius, center.y + radius, center.z + radius); // stretch out our extents in z so that we get all of the avatars minima.z -= _viewFrustum.getFarClip() * 0.5f; @@ -2230,7 +2234,7 @@ void Application::updateShadowMap() { _shadowViewFrustum.setEyeOffsetPosition(glm::vec3()); _shadowViewFrustum.setEyeOffsetOrientation(glm::quat()); _shadowViewFrustum.calculate(); - + glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); @@ -2285,19 +2289,19 @@ void Application::setupWorldLight() { QImage Application::renderAvatarBillboard() { _textureCache.getPrimaryFramebufferObject()->bind(); - + glDisable(GL_BLEND); const int BILLBOARD_SIZE = 64; renderRearViewMirror(QRect(0, _glWidget->height() - BILLBOARD_SIZE, BILLBOARD_SIZE, BILLBOARD_SIZE), true); - + QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32); glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits()); - + glEnable(GL_BLEND); - + _textureCache.getPrimaryFramebufferObject()->release(); - + return image; } @@ -2398,7 +2402,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { "Application::displaySide() ... metavoxels..."); _metavoxels.render(); } - + if (Menu::getInstance()->isOptionChecked(MenuOption::BuckyBalls)) { PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide() ... bucky balls..."); @@ -2411,7 +2415,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { "Application::displaySide() ... particles..."); _particles.render(); } - + // render the ambient occlusion effect if enabled if (Menu::getInstance()->isOptionChecked(MenuOption::AmbientOcclusion)) { PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), @@ -2455,7 +2459,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { // give external parties a change to hook in emit renderingInWorldInterface(); - + // render JS/scriptable overlays _overlays.render3D(); } @@ -2536,8 +2540,8 @@ void Application::displayOverlay() { char frameTimer[10]; quint64 mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5); sprintf(frameTimer, "%d\n", (int)(mSecsNow % 1000)); - int timerBottom = - (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && + int timerBottom = + (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) ? 80 : 20; drawText(_glWidget->width() - 100, _glWidget->height() - timerBottom, 0.30f, 1.0f, 0.f, frameTimer, WHITE_TEXT); @@ -2552,7 +2556,7 @@ void Application::displayOverlay() { void Application::displayStatsBackground(unsigned int rgba, int x, int y, int width, int height) { glBegin(GL_QUADS); glColor4f(((rgba >> 24) & 0xff) / 255.0f, - ((rgba >> 16) & 0xff) / 255.0f, + ((rgba >> 16) & 0xff) / 255.0f, ((rgba >> 8) & 0xff) / 255.0f, (rgba & 0xff) / 255.0f); glVertex3f(x, y, 0); @@ -2560,7 +2564,7 @@ void Application::displayStatsBackground(unsigned int rgba, int x, int y, int wi glVertex3f(x + width, y + height, 0); glVertex3f(x , y + height, 0); glEnd(); - glColor4f(1, 1, 1, 1); + glColor4f(1, 1, 1, 1); } // display expanded or contracted stats @@ -2654,12 +2658,12 @@ void Application::displayStats() { (float) (_audio.getNetworkBufferLengthSamplesPerChannel() + (float) _audio.getJitterBufferSamples()) / (float)_audio.getNetworkSampleRate() * 1000.f); drawText(30, _glWidget->height() - 22, 0.10f, 0.f, 2.f, audioJitter, WHITE_TEXT); - - + + char audioPing[30]; sprintf(audioPing, "Audio ping: %d", pingAudio); - - + + char avatarPing[30]; sprintf(avatarPing, "Avatar ping: %d", pingAvatar); char voxelAvgPing[30]; @@ -2697,7 +2701,7 @@ void Application::displayStats() { } else { // longhand way sprintf(avatarPosition, "Position: %.1f, %.1f, %.1f", avatarPos.x, avatarPos.y, avatarPos.z); - } + } char avatarVelocity[30]; sprintf(avatarVelocity, "Velocity: %.1f", glm::length(_myAvatar->getVelocity())); char avatarBodyYaw[30]; @@ -2723,7 +2727,7 @@ void Application::displayStats() { verticalOffset += STATS_PELS_PER_LINE; drawText(horizontalOffset, verticalOffset, 0.10f, 0.f, 2.f, avatarMixerStats, WHITE_TEXT); - + stringstream downloadStats; downloadStats << "Downloads: "; foreach (Resource* resource, ResourceCache::getLoadingRequests()) { @@ -2731,7 +2735,7 @@ void Application::displayStats() { downloadStats << roundf(resource->getProgress() * MAXIMUM_PERCENTAGE) << "% "; } downloadStats << "(" << ResourceCache::getPendingRequestCount() << " pending)"; - + verticalOffset += STATS_PELS_PER_LINE; drawText(horizontalOffset, verticalOffset, 0.10f, 0.f, 2.f, downloadStats.str().c_str(), WHITE_TEXT); } @@ -2751,7 +2755,7 @@ void Application::displayStats() { drawText(horizontalOffset, verticalOffset, 0.10f, 0.f, 2.f, (char*)voxelStats.str().c_str(), WHITE_TEXT); voxelStats.str(""); - voxelStats << + voxelStats << "Geometry RAM: " << _voxels.getVoxelMemoryUsageRAM() / 1000000.f << "MB / " << "VBO: " << _voxels.getVoxelMemoryUsageVBO() / 1000000.f << "MB"; if (_voxels.hasVoxelMemoryUsageGPU()) { @@ -2803,7 +2807,7 @@ void Application::displayStats() { totalNodes += stats.getTotalElements(); if (_statsExpanded) { totalInternal += stats.getTotalInternal(); - totalLeaves += stats.getTotalLeaves(); + totalLeaves += stats.getTotalLeaves(); } } if (_statsExpanded) { @@ -2827,7 +2831,7 @@ void Application::displayStats() { QString packetsString = locale.toString((int)voxelPacketsToProcess); QString maxString = locale.toString((int)_recentMaxPackets); voxelStats << "Voxel Packets to Process: " << qPrintable(packetsString) - << " [Recent Max: " << qPrintable(maxString) << "]"; + << " [Recent Max: " << qPrintable(maxString) << "]"; verticalOffset += STATS_PELS_PER_LINE; drawText(horizontalOffset, verticalOffset, 0.10f, 0.f, 2.f, (char*)voxelStats.str().c_str(), WHITE_TEXT); } @@ -2989,12 +2993,12 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { _mirrorCamera.setFieldOfView(BILLBOARD_FIELD_OF_VIEW); // degees _mirrorCamera.setDistance(BILLBOARD_DISTANCE * _myAvatar->getScale()); _mirrorCamera.setTargetPosition(_myAvatar->getPosition()); - + } else if (_rearMirrorTools->getZoomLevel() == BODY) { _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees _mirrorCamera.setDistance(MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale()); _mirrorCamera.setTargetPosition(_myAvatar->getChestPosition()); - + } else { // HEAD zoom level _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees _mirrorCamera.setDistance(MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale()); @@ -3009,7 +3013,7 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { } } _mirrorCamera.setAspectRatio((float)region.width() / region.height()); - + _mirrorCamera.setTargetRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f))); _mirrorCamera.update(1.0f/_fps); @@ -3054,7 +3058,7 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { if (!billboard) { _rearMirrorTools->render(false); } - + // reset Viewport and projection matrix glViewport(0, 0, _glWidget->width(), _glWidget->height()); glDisable(GL_SCISSOR_TEST); @@ -3274,14 +3278,14 @@ void Application::setMenuShortcutsEnabled(bool enabled) { } void Application::updateWindowTitle(){ - + QString buildVersion = " (build " + applicationVersion() + ")"; NodeList* nodeList = NodeList::getInstance(); - + QString username = AccountManager::getInstance().getUsername(); QString title = QString() + (!username.isEmpty() ? username + " " : QString()) + nodeList->getSessionUUID().toString() + " @ " + nodeList->getDomainInfo().getHostname() + buildVersion; - + qDebug("Application title set to: %s", title.toStdString().c_str()); _window->setWindowTitle(title); } @@ -3296,7 +3300,7 @@ void Application::domainChanged(const QString& domainHostname) { _voxelServerJurisdictions.clear(); _octreeServerSceneStats.clear(); _particleServerJurisdictions.clear(); - + // reset the particle renderer _particles.clear(); @@ -3306,12 +3310,12 @@ void Application::domainChanged(const QString& domainHostname) { void Application::connectedToDomain(const QString& hostname) { AccountManager& accountManager = AccountManager::getInstance(); - + if (accountManager.isLoggedIn()) { // update our domain-server with the data-server we're logged in with - + QString domainPutJsonString = "{\"address\":{\"domain\":\"" + hostname + "\"}}"; - + accountManager.authenticatedRequest("/api/v1/users/address", QNetworkAccessManager::PutOperation, JSONCallbackParameters(), domainPutJsonString.toUtf8()); } @@ -3476,13 +3480,13 @@ void Application::loadScripts() { // loads all saved scripts QSettings* settings = new QSettings(this); int size = settings->beginReadArray("Settings"); - + for (int i = 0; i < size; ++i){ settings->setArrayIndex(i); QString string = settings->value("script").toString(); loadScript(string); } - + settings->endArray(); } @@ -3497,42 +3501,72 @@ void Application::saveScripts() { // saves all current running scripts QSettings* settings = new QSettings(this); settings->beginWriteArray("Settings"); - for (int i = 0; i < _activeScripts.size(); ++i){ + for (int i = 0; i < getRunningScripts().size(); ++i){ settings->setArrayIndex(i); - settings->setValue("script", _activeScripts.at(i)); + settings->setValue("script", getRunningScripts().at(i)); } - + settings->endArray(); } void Application::stopAllScripts() { // stops all current running scripts - QList scriptActions = Menu::getInstance()->getActiveScriptsMenu()->actions(); - foreach (QAction* scriptAction, scriptActions) { - scriptAction->activate(QAction::Trigger); - qDebug() << "stopping script..." << scriptAction->text(); + for (int i = 0; i < _scriptEnginesHash.size(); ++i) { + _scriptEnginesHash.values().at(i)->stop(); + qDebug() << "stopping script..." << getRunningScripts().at(i); } - _activeScripts.clear(); + _scriptEnginesHash.clear(); + _runningScriptsWidget->setRunningScripts(getRunningScripts()); +} + +void Application::stopScript(const QString &scriptName) +{ + _scriptEnginesHash.value(scriptName)->stop(); + qDebug() << "stopping script..." << scriptName; + _scriptEnginesHash.remove(scriptName); + _runningScriptsWidget->setRunningScripts(getRunningScripts()); } void Application::reloadAllScripts() { // remember all the current scripts so we can reload them - QStringList reloadList = _activeScripts; + QStringList reloadList = getRunningScripts(); // reloads all current running scripts - QList scriptActions = Menu::getInstance()->getActiveScriptsMenu()->actions(); - foreach (QAction* scriptAction, scriptActions) { - scriptAction->activate(QAction::Trigger); - qDebug() << "stopping script..." << scriptAction->text(); - } + stopAllScripts(); - // NOTE: we don't need to clear the _activeScripts list because that is handled on script shutdown. - foreach (QString scriptName, reloadList){ qDebug() << "reloading script..." << scriptName; loadScript(scriptName); } } +void Application::toggleRunningScriptsWidget() +{ + if (!_runningScriptsWidget->toggleViewAction()->isChecked()) { + _runningScriptsWidget->move(_window->geometry().topLeft().x(), _window->geometry().topLeft().y()); + _runningScriptsWidget->resize(0, _window->height()); + _runningScriptsWidget->toggleViewAction()->trigger(); + _runningScriptsWidget->grabKeyboard(); + + QPropertyAnimation* slideAnimation = new QPropertyAnimation(_runningScriptsWidget, "geometry", _runningScriptsWidget); + slideAnimation->setStartValue(_runningScriptsWidget->geometry()); + slideAnimation->setEndValue(QRect(_window->geometry().topLeft().x(), _window->geometry().topLeft().y(), + 310, _runningScriptsWidget->height())); + slideAnimation->setDuration(250); + slideAnimation->start(QAbstractAnimation::DeleteWhenStopped); + } else { + _runningScriptsWidget->releaseKeyboard(); + + QPropertyAnimation* slideAnimation = new QPropertyAnimation(_runningScriptsWidget, "geometry", _runningScriptsWidget); + slideAnimation->setStartValue(_runningScriptsWidget->geometry()); + slideAnimation->setEndValue(QRect(_window->geometry().topLeft().x(), _window->geometry().topLeft().y(), + 0, _runningScriptsWidget->height())); + slideAnimation->setDuration(250); + slideAnimation->start(QAbstractAnimation::DeleteWhenStopped); + + QTimer::singleShot(260, _runningScriptsWidget->toggleViewAction(), SLOT(trigger())); + } +} + void Application::uploadFST() { FstReader reader; if (reader.zip()) { @@ -3540,29 +3574,17 @@ void Application::uploadFST() { } } -void Application::removeScriptName(const QString& fileNameString) { - _activeScripts.removeOne(fileNameString); -} - -void Application::cleanupScriptMenuItem(const QString& scriptMenuName) { - Menu::getInstance()->removeAction(Menu::getInstance()->getActiveScriptsMenu(), scriptMenuName); -} - void Application::loadScript(const QString& scriptName) { // start the script on a new thread... - bool wantMenuItems = true; // tells the ScriptEngine object to add menu items for itself - ScriptEngine* scriptEngine = new ScriptEngine(QUrl(scriptName), wantMenuItems, &_controllerScriptingInterface); + ScriptEngine* scriptEngine = new ScriptEngine(QUrl(scriptName), &_controllerScriptingInterface); + _scriptEnginesHash.insert(scriptName, scriptEngine); if (!scriptEngine->hasScript()) { qDebug() << "Application::loadScript(), script failed to load..."; return; } - _activeScripts.append(scriptName); - - // add a stop menu item - Menu::getInstance()->addActionToQMenuAndActionHash(Menu::getInstance()->getActiveScriptsMenu(), - scriptEngine->getScriptMenuName(), 0, scriptEngine, SLOT(stop())); + _runningScriptsWidget->setRunningScripts(getRunningScripts()); // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so // we can use the same ones from the application. @@ -3570,7 +3592,7 @@ void Application::loadScript(const QString& scriptName) { scriptEngine->getVoxelsScriptingInterface()->setVoxelTree(_voxels.getTree()); scriptEngine->getParticlesScriptingInterface()->setPacketSender(&_particleEditSender); scriptEngine->getParticlesScriptingInterface()->setParticleTree(_particles.getTree()); - + // hook our avatar object into this script engine scriptEngine->setAvatarData(_myAvatar, "MyAvatar"); // leave it as a MyAvatar class to expose thrust features @@ -3595,8 +3617,6 @@ void Application::loadScript(const QString& scriptName) { // when the thread is terminated, add both scriptEngine and thread to the deleteLater queue connect(scriptEngine, SIGNAL(finished(const QString&)), scriptEngine, SLOT(deleteLater())); connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater())); - connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(removeScriptName(const QString&))); - connect(scriptEngine, SIGNAL(cleanupMenuItem(const QString&)), this, SLOT(cleanupScriptMenuItem(const QString&))); // when the application is about to quit, stop our script engine so it unwinds properly connect(this, SIGNAL(aboutToQuit()), scriptEngine, SLOT(stop())); @@ -3620,12 +3640,12 @@ void Application::loadDialog() { suggestedName = _previousScriptLocation; } - QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), suggestedName, + QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), suggestedName, tr("JavaScript Files (*.js)")); if (!fileNameString.isEmpty()) { _previousScriptLocation = fileNameString; } - + loadScript(fileNameString); } @@ -3636,7 +3656,7 @@ void Application::loadScriptURLDialog() { scriptURLDialog.setLabelText("Script:"); scriptURLDialog.setWindowFlags(Qt::Sheet); const float DIALOG_RATIO_OF_WINDOW = 0.30f; - scriptURLDialog.resize(scriptURLDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, + scriptURLDialog.resize(scriptURLDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, scriptURLDialog.size().height()); int dialogReturn = scriptURLDialog.exec(); @@ -3674,29 +3694,29 @@ void Application::checkVersion() { } void Application::parseVersionXml() { - + #ifdef Q_OS_WIN32 QString operatingSystem("win"); #endif - + #ifdef Q_OS_MAC QString operatingSystem("mac"); #endif - + #ifdef Q_OS_LINUX QString operatingSystem("ubuntu"); #endif - + QString releaseDate; QString releaseNotes; QString latestVersion; QUrl downloadUrl; QObject* sender = QObject::sender(); - + QXmlStreamReader xml(qobject_cast(sender)); while (!xml.atEnd() && !xml.hasError()) { QXmlStreamReader::TokenType token = xml.readNext(); - + if (token == QXmlStreamReader::StartElement) { if (xml.name() == "ReleaseDate") { xml.readNext(); diff --git a/interface/src/Application.h b/interface/src/Application.h index bab7578ca4..b6a9618cd8 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -65,6 +66,7 @@ #include "ui/LogDialog.h" #include "ui/UpdateDialog.h" #include "ui/overlays/Overlays.h" +#include "ui/RunningScriptsWidget.h" #include "voxels/VoxelFade.h" #include "voxels/VoxelHideShowThread.h" #include "voxels/VoxelImporter.h" @@ -112,7 +114,7 @@ public: ~Application(); void restoreSizeAndPosition(); - void loadScript(const QString& fileNameString); + void loadScript(const QString& fileNameString); void loadScripts(); void storeSizeAndPosition(); void clearScriptsBeforeRunning(); @@ -136,9 +138,9 @@ public: void wheelEvent(QWheelEvent* event); void dropEvent(QDropEvent *event); - + bool event(QEvent* event); - + void makeVoxel(glm::vec3 position, float scale, unsigned char red, @@ -226,6 +228,8 @@ public: void skipVersion(QString latestVersion); + QStringList getRunningScripts() { return _scriptEnginesHash.keys(); } + signals: /// Fired when we're simulating; allows external parties to hook in. @@ -233,10 +237,10 @@ signals: /// Fired when we're rendering in-world interface elements; allows external parties to hook in. void renderingInWorldInterface(); - + /// Fired when the import window is closed void importDone(); - + public slots: void domainChanged(const QString& domainHostname); void updateWindowTitle(); @@ -259,31 +263,30 @@ public slots: void toggleLogDialog(); void initAvatarAndViewFrustum(); void stopAllScripts(); + void stopScript(const QString& scriptName); void reloadAllScripts(); - + void toggleRunningScriptsWidget(); + void uploadFST(); private slots: void timer(); void idle(); - + void connectedToDomain(const QString& hostname); void setFullscreen(bool fullscreen); void setEnable3DTVMode(bool enable3DTVMode); void cameraMenuChanged(); - + glm::vec2 getScaledScreenPoint(glm::vec2 projectedPoint); void closeMirrorView(); void restoreMirrorView(); void shrinkMirrorView(); void resetSensors(); - - void parseVersionXml(); - void removeScriptName(const QString& fileNameString); - void cleanupScriptMenuItem(const QString& scriptMenuName); + void parseVersionXml(); private: void resetCamerasOnResizeGL(Camera& camera, int width, int height); @@ -354,7 +357,7 @@ private: bool _statsExpanded; BandwidthMeter _bandwidthMeter; - + QThread* _nodeThread; DatagramProcessor _datagramProcessor; @@ -373,7 +376,7 @@ private: timeval _lastTimeUpdated; bool _justStarted; Stars _stars; - + BuckyBalls _buckyBalls; VoxelSystem _voxels; @@ -407,7 +410,6 @@ private: Visage _visage; SixenseManager _sixenseManager; - QStringList _activeScripts; Camera _myCamera; // My view onto the world Camera _viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode @@ -491,10 +493,13 @@ private: void displayUpdateDialog(); bool shouldSkipVersion(QString latestVersion); void takeSnapshot(); - + TouchEvent _lastTouchEvent; - + Overlays _overlays; + + QPointer _runningScriptsWidget; + QHash _scriptEnginesHash; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index ec20401fef..313a6728fb 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -87,7 +87,7 @@ Menu::Menu() : _loginAction(NULL) { Application *appInstance = Application::getInstance(); - + QMenu* fileMenu = addMenu("File"); #ifdef Q_OS_MAC @@ -100,23 +100,24 @@ Menu::Menu() : #endif AccountManager& accountManager = AccountManager::getInstance(); - + _loginAction = addActionToQMenuAndActionHash(fileMenu, MenuOption::Logout); - + // call our toggle login function now so the menu option is setup properly toggleLoginMenuItem(); - + // connect to the appropriate slots of the AccountManager so that we can change the Login/Logout menu item connect(&accountManager, &AccountManager::accessTokenChanged, this, &Menu::toggleLoginMenuItem); connect(&accountManager, &AccountManager::logoutComplete, this, &Menu::toggleLoginMenuItem); addDisabledActionAndSeparator(fileMenu, "Scripts"); addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog())); - addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScriptURL, + addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScriptURL, Qt::CTRL | Qt::SHIFT | Qt::Key_O, appInstance, SLOT(loadScriptURLDialog())); addActionToQMenuAndActionHash(fileMenu, MenuOption::StopAllScripts, 0, appInstance, SLOT(stopAllScripts())); addActionToQMenuAndActionHash(fileMenu, MenuOption::ReloadAllScripts, 0, appInstance, SLOT(reloadAllScripts())); - _activeScriptsMenu = fileMenu->addMenu("Running Scripts"); + addActionToQMenuAndActionHash(fileMenu, MenuOption::RunningScripts, Qt::CTRL | Qt::Key_J, + appInstance, SLOT(toggleRunningScriptsWidget())); addDisabledActionAndSeparator(fileMenu, "Go"); addActionToQMenuAndActionHash(fileMenu, @@ -147,7 +148,7 @@ Menu::Menu() : addDisabledActionAndSeparator(fileMenu, "Upload Avatar Model"); addActionToQMenuAndActionHash(fileMenu, MenuOption::UploadFST, 0, Application::getInstance(), SLOT(uploadFST())); - + addDisabledActionAndSeparator(fileMenu, "Settings"); addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsImport, 0, this, SLOT(importSettings())); addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsExport, 0, this, SLOT(exportSettings())); @@ -172,8 +173,8 @@ Menu::Menu() : addDisabledActionAndSeparator(editMenu, "Physics"); addCheckableActionToQMenuAndActionHash(editMenu, MenuOption::Gravity, Qt::SHIFT | Qt::Key_G, false); - - + + addAvatarCollisionSubMenu(editMenu); @@ -207,7 +208,7 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Mirror, Qt::SHIFT | Qt::Key_H, true); addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::FullscreenMirror, Qt::Key_H, false, appInstance, SLOT(cameraMenuChanged())); - + addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Enable3DTVMode, 0, false, appInstance, @@ -333,16 +334,16 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(renderDebugMenu, MenuOption::PipelineWarnings, Qt::CTRL | Qt::SHIFT | Qt::Key_P); addCheckableActionToQMenuAndActionHash(renderDebugMenu, MenuOption::SuppressShortTimings, Qt::CTRL | Qt::SHIFT | Qt::Key_S); - addCheckableActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::CullSharedFaces, - Qt::CTRL | Qt::SHIFT | Qt::Key_C, + addCheckableActionToQMenuAndActionHash(renderDebugMenu, + MenuOption::CullSharedFaces, + Qt::CTRL | Qt::SHIFT | Qt::Key_C, false, appInstance->getVoxels(), SLOT(cullSharedFaces())); - addCheckableActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::ShowCulledSharedFaces, - Qt::CTRL | Qt::SHIFT | Qt::Key_X, + addCheckableActionToQMenuAndActionHash(renderDebugMenu, + MenuOption::ShowCulledSharedFaces, + Qt::CTRL | Qt::SHIFT | Qt::Key_X, false, appInstance->getVoxels(), SLOT(showCulledSharedFaces())); @@ -360,14 +361,14 @@ Menu::Menu() : false, appInstance->getAudio(), SLOT(toggleMute())); - + addActionToQMenuAndActionHash(developerMenu, MenuOption::PasteToVoxel, Qt::CTRL | Qt::SHIFT | Qt::Key_V, this, SLOT(pasteToVoxel())); connect(appInstance->getAudio(), SIGNAL(muteToggled()), this, SLOT(audioMuteToggled())); - + #ifndef Q_OS_MAC QMenu* helpMenu = addMenu("Help"); QAction* helpAction = helpMenu->addAction(MenuOption::AboutApp); @@ -571,7 +572,7 @@ void Menu::addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& QAction* separatorText = new QAction(actionName,destinationMenu); separatorText->setEnabled(false); destinationMenu->insertAction(actionBefore, separatorText); - + } else { destinationMenu->addSeparator(); (destinationMenu->addAction(actionName))->setEnabled(false); @@ -623,7 +624,7 @@ QAction* Menu::addCheckableActionToQMenuAndActionHash(QMenu* destinationMenu, const char* member, int menuItemLocation) { - QAction* action = addActionToQMenuAndActionHash(destinationMenu, actionName, shortcut, receiver, member, + QAction* action = addActionToQMenuAndActionHash(destinationMenu, actionName, shortcut, receiver, member, QAction::NoRole, menuItemLocation); action->setCheckable(true); action->setChecked(checked); @@ -677,35 +678,35 @@ const float DIALOG_RATIO_OF_WINDOW = 0.30f; void Menu::loginForCurrentDomain() { QDialog loginDialog(Application::getInstance()->getWindow()); loginDialog.setWindowTitle("Login"); - + QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); loginDialog.setLayout(layout); loginDialog.setWindowFlags(Qt::Sheet); - + QFormLayout* form = new QFormLayout(); layout->addLayout(form, 1); - + QLineEdit* loginLineEdit = new QLineEdit(); loginLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); form->addRow("Login:", loginLineEdit); - + QLineEdit* passwordLineEdit = new QLineEdit(); passwordLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); passwordLineEdit->setEchoMode(QLineEdit::Password); form->addRow("Password:", passwordLineEdit); - + QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); loginDialog.connect(buttons, SIGNAL(accepted()), SLOT(accept())); loginDialog.connect(buttons, SIGNAL(rejected()), SLOT(reject())); layout->addWidget(buttons); - + int dialogReturn = loginDialog.exec(); - + if (dialogReturn == QDialog::Accepted && !loginLineEdit->text().isEmpty() && !passwordLineEdit->text().isEmpty()) { // attempt to get an access token given this username and password AccountManager::getInstance().requestAccessToken(loginLineEdit->text(), passwordLineEdit->text()); } - + sendFakeEnterEvent(); } @@ -713,19 +714,19 @@ void Menu::editPreferences() { Application* applicationInstance = Application::getInstance(); ModelBrowser headBrowser(Head); ModelBrowser skeletonBrowser(Skeleton); - + const QString BROWSE_BUTTON_TEXT = "Browse"; QDialog dialog(applicationInstance->getWindow()); dialog.setWindowTitle("Interface Preferences"); - + QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); dialog.setLayout(layout); - + QFormLayout* form = new QFormLayout(); layout->addLayout(form, 1); - + QHBoxLayout headModelLayout; QString faceURLString = applicationInstance->getAvatar()->getHead()->getFaceModel().getURL().toString(); QLineEdit headURLEdit(faceURLString); @@ -737,7 +738,7 @@ void Menu::editPreferences() { headModelLayout.addWidget(&headURLEdit); headModelLayout.addWidget(&headBrowseButton); form->addRow("Head URL:", &headModelLayout); - + QHBoxLayout skeletonModelLayout; QString skeletonURLString = applicationInstance->getAvatar()->getSkeletonModel().getURL().toString(); QLineEdit skeletonURLEdit(skeletonURLString); @@ -749,7 +750,7 @@ void Menu::editPreferences() { skeletonModelLayout.addWidget(&skeletonURLEdit); skeletonModelLayout.addWidget(&SkeletonBrowseButton); form->addRow("Skeleton URL:", &skeletonModelLayout); - + QString displayNameString = applicationInstance->getAvatar()->getDisplayName(); QLineEdit* displayNameEdit = new QLineEdit(displayNameString); @@ -826,12 +827,12 @@ void Menu::editPreferences() { } QString displayNameStr(displayNameEdit->text()); - + if (displayNameStr != displayNameString) { applicationInstance->getAvatar()->setDisplayName(displayNameStr); shouldDispatchIdentityPacket = true; } - + if (shouldDispatchIdentityPacket) { applicationInstance->getAvatar()->sendIdentityPacket(); } @@ -864,10 +865,10 @@ void Menu::editPreferences() { void Menu::goToDomain(const QString newDomain) { if (NodeList::getInstance()->getDomainInfo().getHostname() != newDomain) { - + // send a node kill request, indicating to other clients that they should play the "disappeared" effect Application::getInstance()->getAvatar()->sendKillAvatar(); - + // give our nodeList the new domain-server hostname NodeList::getInstance()->getDomainInfo().setHostname(newDomain); } @@ -897,7 +898,7 @@ void Menu::goToDomainDialog() { // the user input a new hostname, use that newHostname = domainDialog.textValue(); } - + goToDomain(newHostname); } @@ -913,7 +914,7 @@ bool Menu::goToDestination(QString destination) { } void Menu::goTo() { - + QInputDialog gotoDialog(Application::getInstance()->getWindow()); gotoDialog.setWindowTitle("Go to"); gotoDialog.setLabelText("Destination:"); @@ -921,7 +922,7 @@ void Menu::goTo() { gotoDialog.setTextValue(destination); gotoDialog.setWindowFlags(Qt::Sheet); gotoDialog.resize(gotoDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, gotoDialog.size().height()); - + int dialogReturn = gotoDialog.exec(); if (dialogReturn == QDialog::Accepted && !gotoDialog.textValue().isEmpty()) { goToUser(gotoDialog.textValue()); @@ -1070,7 +1071,7 @@ void Menu::toggleLoginMenuItem() { AccountManager& accountManager = AccountManager::getInstance(); disconnect(_loginAction, 0, 0, 0); - + if (accountManager.isLoggedIn()) { // change the menu item to logout _loginAction->setText("Logout " + accountManager.getUsername()); @@ -1078,7 +1079,7 @@ void Menu::toggleLoginMenuItem() { } else { // change the menu item to login _loginAction->setText("Login"); - + connect(_loginAction, &QAction::triggered, this, &Menu::loginForCurrentDomain); } } @@ -1185,7 +1186,7 @@ QString Menu::getLODFeedbackText() { } break; } - // distance feedback + // distance feedback float voxelSizeScale = getVoxelSizeScale(); float relativeToDefault = voxelSizeScale / DEFAULT_OCTREE_SIZE_SCALE; QString result; @@ -1200,7 +1201,7 @@ QString Menu::getLODFeedbackText() { } void Menu::autoAdjustLOD(float currentFPS) { - // NOTE: our first ~100 samples at app startup are completely all over the place, and we don't + // NOTE: our first ~100 samples at app startup are completely all over the place, and we don't // really want to count them in our average, so we will ignore the real frame rates and stuff // our moving average with simulated good data const int IGNORE_THESE_SAMPLES = 100; @@ -1212,7 +1213,7 @@ void Menu::autoAdjustLOD(float currentFPS) { _fastFPSAverage.updateAverage(currentFPS); quint64 now = usecTimestampNow(); - + const quint64 ADJUST_AVATAR_LOD_DOWN_DELAY = 1000 * 1000; if (_fastFPSAverage.getAverage() < ADJUST_LOD_DOWN_FPS) { if (now - _lastAvatarDetailDrop > ADJUST_AVATAR_LOD_DOWN_DELAY) { @@ -1231,11 +1232,11 @@ void Menu::autoAdjustLOD(float currentFPS) { _avatarLODDistanceMultiplier = qMax(MINIMUM_DISTANCE_MULTIPLIER, _avatarLODDistanceMultiplier - DISTANCE_DECREASE_RATE); } - + bool changed = false; quint64 elapsed = now - _lastAdjust; - if (elapsed > ADJUST_LOD_DOWN_DELAY && _fpsAverage.getAverage() < ADJUST_LOD_DOWN_FPS + if (elapsed > ADJUST_LOD_DOWN_DELAY && _fpsAverage.getAverage() < ADJUST_LOD_DOWN_FPS && _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) { _voxelSizeScale *= ADJUST_LOD_DOWN_BY; @@ -1248,7 +1249,7 @@ void Menu::autoAdjustLOD(float currentFPS) { << "_voxelSizeScale=" << _voxelSizeScale; } - if (elapsed > ADJUST_LOD_UP_DELAY && _fpsAverage.getAverage() > ADJUST_LOD_UP_FPS + if (elapsed > ADJUST_LOD_UP_DELAY && _fpsAverage.getAverage() > ADJUST_LOD_UP_FPS && _voxelSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) { _voxelSizeScale *= ADJUST_LOD_UP_BY; if (_voxelSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) { @@ -1259,7 +1260,7 @@ void Menu::autoAdjustLOD(float currentFPS) { qDebug() << "adjusting LOD up... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage() << "_voxelSizeScale=" << _voxelSizeScale; } - + if (changed) { if (_lodToolsDialog) { _lodToolsDialog->reloadSliders(); @@ -1337,13 +1338,13 @@ void Menu::addAvatarCollisionSubMenu(QMenu* overMenu) { Application* appInstance = Application::getInstance(); QObject* avatar = appInstance->getAvatar(); - addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithEnvironment, + addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithEnvironment, 0, false, avatar, SLOT(updateCollisionFlags())); - addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithAvatars, + addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithAvatars, 0, true, avatar, SLOT(updateCollisionFlags())); - addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithVoxels, + addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithVoxels, 0, false, avatar, SLOT(updateCollisionFlags())); - addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithParticles, + addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithParticles, 0, true, avatar, SLOT(updateCollisionFlags())); } @@ -1352,9 +1353,9 @@ QAction* Menu::getActionFromName(const QString& menuName, QMenu* menu) { if (menu) { menuActions = menu->actions(); } else { - menuActions = actions(); + menuActions = actions(); } - + foreach (QAction* menuAction, menuActions) { if (menuName == menuAction->text()) { return menuAction; @@ -1461,7 +1462,7 @@ QMenu* Menu::addMenu(const QString& menuName) { void Menu::removeMenu(const QString& menuName) { QAction* action = getMenuAction(menuName); - + // only proceed if the menu actually exists if (action) { QString finalMenuPart; @@ -1513,7 +1514,7 @@ void Menu::addMenuItem(const MenuItemProperties& properties) { if (!properties.shortcutKeySequence.isEmpty()) { shortcut = new QShortcut(properties.shortcutKeySequence, this); } - + // check for positioning requests int requestedPosition = properties.position; if (requestedPosition == UNSPECIFIED_POSITION && !properties.beforeItem.isEmpty()) { @@ -1527,13 +1528,13 @@ void Menu::addMenuItem(const MenuItemProperties& properties) { requestedPosition = afterPosition + 1; } } - + QAction* menuItemAction = NULL; if (properties.isSeparator) { addDisabledActionAndSeparator(menuObj, properties.menuItemName, requestedPosition); } else if (properties.isCheckable) { menuItemAction = addCheckableActionToQMenuAndActionHash(menuObj, properties.menuItemName, - properties.shortcutKeySequence, properties.isChecked, + properties.shortcutKeySequence, properties.isChecked, MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered()), requestedPosition); } else { menuItemAction = addActionToQMenuAndActionHash(menuObj, properties.menuItemName, properties.shortcutKeySequence, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index c7c4c6ecea..b69d44061d 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -95,8 +95,6 @@ public: // User Tweakable PPS from Voxel Server int getMaxVoxelPacketsPerSecond() const { return _maxVoxelPacketsPerSecond; } - QMenu* getActiveScriptsMenu() { return _activeScriptsMenu;} - QAction* addActionToQMenuAndActionHash(QMenu* destinationMenu, const QString& actionName, const QKeySequence& shortcut = 0, @@ -124,7 +122,7 @@ public slots: void goTo(); void goToUser(const QString& user); void pasteToVoxel(); - + void toggleLoginMenuItem(); QMenu* addMenu(const QString& menuName); @@ -166,7 +164,7 @@ private: void scanMenu(QMenu* menu, settingsAction modifySetting, QSettings* set); /// helper method to have separators with labels that are also compatible with OS X - void addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& actionName, + void addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& actionName, int menuItemLocation = UNSPECIFIED_POSITION); QAction* addCheckableActionToQMenuAndActionHash(QMenu* destinationMenu, @@ -189,7 +187,7 @@ private: int findPositionOfMenuItem(QMenu* menu, const QString& searchMenuItem); int positionBeforeSeparatorIfNeeded(QMenu* menu, int requestedPosition); QMenu* getMenu(const QString& menuName); - + QHash _actionHash; int _audioJitterBufferSamples; /// number of extra samples to wait before starting audio playback @@ -208,7 +206,6 @@ private: int _boundaryLevelAdjust; QAction* _useVoxelShader; int _maxVoxelPacketsPerSecond; - QMenu* _activeScriptsMenu; QString replaceLastOccurrence(QChar search, QChar replace, QString string); quint64 _lastAdjust; quint64 _lastAvatarDetailDrop; @@ -290,6 +287,7 @@ namespace MenuOption { const QString RenderSkeletonCollisionProxies = "Skeleton Collision Proxies"; const QString RenderHeadCollisionProxies = "Head Collision Proxies"; const QString ResetAvatarSize = "Reset Avatar Size"; + const QString RunningScripts = "Running Scripts"; const QString RunTimingTests = "Run Timing Tests"; const QString SettingsImport = "Import Settings"; const QString Shadows = "Shadows"; diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp new file mode 100644 index 0000000000..2238cab2df --- /dev/null +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -0,0 +1,203 @@ +// +// RunningScripts.cpp +// interface +// +// Created by Mohammed Nafees on 03/28/2014. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. + +#include "ui_runningScriptsWidget.h" +#include "RunningScriptsWidget.h" + +#include +#include + +#include "Application.h" + +RunningScriptsWidget::RunningScriptsWidget(QDockWidget *parent) : + QDockWidget(parent), + ui(new Ui::RunningScriptsWidget) +{ + ui->setupUi(this); + + // remove the title bar (see the Qt docs on setTitleBarWidget) + setTitleBarWidget(new QWidget()); + + ui->runningScriptsTableWidget->setColumnCount(2); + ui->runningScriptsTableWidget->verticalHeader()->setVisible(false); + ui->runningScriptsTableWidget->horizontalHeader()->setVisible(false); + ui->runningScriptsTableWidget->setSelectionMode(QAbstractItemView::NoSelection); + ui->runningScriptsTableWidget->setShowGrid(false); + ui->runningScriptsTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui->runningScriptsTableWidget->setColumnWidth(0, 235); + ui->runningScriptsTableWidget->setColumnWidth(1, 25); + connect(ui->runningScriptsTableWidget, &QTableWidget::cellClicked, this, &RunningScriptsWidget::stopScript); + + ui->recentlyLoadedScriptsTableWidget->setColumnCount(2); + ui->recentlyLoadedScriptsTableWidget->verticalHeader()->setVisible(false); + ui->recentlyLoadedScriptsTableWidget->horizontalHeader()->setVisible(false); + ui->recentlyLoadedScriptsTableWidget->setSelectionMode(QAbstractItemView::NoSelection); + ui->recentlyLoadedScriptsTableWidget->setShowGrid(false); + ui->recentlyLoadedScriptsTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui->recentlyLoadedScriptsTableWidget->setColumnWidth(0, 25); + ui->recentlyLoadedScriptsTableWidget->setColumnWidth(1, 235); + connect(ui->recentlyLoadedScriptsTableWidget, &QTableWidget::cellClicked, + this, &RunningScriptsWidget::loadScript); + + connect(ui->hideWidgetButton, &QPushButton::clicked, + Application::getInstance(), &Application::toggleRunningScriptsWidget); + connect(ui->reloadAllButton, &QPushButton::clicked, + Application::getInstance(), &Application::reloadAllScripts); + connect(ui->stopAllButton, &QPushButton::clicked, + this, &RunningScriptsWidget::allScriptsStopped); +} + +RunningScriptsWidget::~RunningScriptsWidget() +{ + delete ui; +} + +void RunningScriptsWidget::setRunningScripts(const QStringList& list) +{ + ui->runningScriptsTableWidget->setRowCount(list.size()); + + ui->noRunningScriptsLabel->setVisible(list.isEmpty()); + ui->currentlyRunningLabel->setVisible(!list.isEmpty()); + ui->line1->setVisible(!list.isEmpty()); + ui->runningScriptsTableWidget->setVisible(!list.isEmpty()); + ui->reloadAllButton->setVisible(!list.isEmpty()); + ui->stopAllButton->setVisible(!list.isEmpty()); + + for (int i = 0; i < list.size(); ++i) { + QTableWidgetItem *scriptName = new QTableWidgetItem; + scriptName->setText(list.at(i)); + scriptName->setToolTip(list.at(i)); + scriptName->setTextAlignment(Qt::AlignCenter); + QTableWidgetItem *closeIcon = new QTableWidgetItem; + closeIcon->setIcon(QIcon(":/images/kill-script.svg")); + + ui->runningScriptsTableWidget->setItem(i, 0, scriptName); + ui->runningScriptsTableWidget->setItem(i, 1, closeIcon); + } + + createRecentlyLoadedScriptsTable(); +} + +void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) +{ + switch(e->key()) { + case Qt::Key_Escape: + Application::getInstance()->toggleRunningScriptsWidget(); + break; + + case Qt::Key_1: + if (_recentlyLoadedScripts.size() > 0) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(0)); + } + break; + + case Qt::Key_2: + if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 2) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(1)); + } + break; + + case Qt::Key_3: + if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 3) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(2)); + } + break; + + case Qt::Key_4: + if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 4) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(3)); + } + break; + case Qt::Key_5: + if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 5) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(4)); + } + break; + + case Qt::Key_6: + if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 6) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(5)); + } + break; + + case Qt::Key_7: + if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 7) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(6)); + } + break; + case Qt::Key_8: + if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 8) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(7)); + } + break; + + case Qt::Key_9: + if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 9) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(8)); + } + break; + + default: + break; + } +} + +void RunningScriptsWidget::stopScript(int row, int column) +{ + if (column == 1) { // make sure the user has clicked on the close icon + _lastStoppedScript = ui->runningScriptsTableWidget->item(row, 0)->text(); + emit stopScriptName(ui->runningScriptsTableWidget->item(row, 0)->text()); + } +} + +void RunningScriptsWidget::loadScript(int row, int column) +{ + Application::getInstance()->loadScript(ui->recentlyLoadedScriptsTableWidget->item(row, column)->text()); +} + +void RunningScriptsWidget::allScriptsStopped() +{ + QStringList list = Application::getInstance()->getRunningScripts(); + for (int i = 0; i < list.size(); ++i) { + _recentlyLoadedScripts.prepend(list.at(i)); + } + + Application::getInstance()->stopAllScripts(); +} + +void RunningScriptsWidget::createRecentlyLoadedScriptsTable() +{ + if (!_recentlyLoadedScripts.contains(_lastStoppedScript) && !_lastStoppedScript.isEmpty()) { + _recentlyLoadedScripts.prepend(_lastStoppedScript); + _lastStoppedScript = ""; + } + + for (int i = 0; i < _recentlyLoadedScripts.size(); ++i) { + if (Application::getInstance()->getRunningScripts().contains(_recentlyLoadedScripts.at(i))) { + _recentlyLoadedScripts.removeOne(_recentlyLoadedScripts.at(i)); + } + } + + ui->recentlyLoadedLabel->setVisible(!_recentlyLoadedScripts.isEmpty()); + ui->line2->setVisible(!_recentlyLoadedScripts.isEmpty()); + ui->recentlyLoadedScriptsTableWidget->setVisible(!_recentlyLoadedScripts.isEmpty()); + ui->recentlyLoadedInstruction->setVisible(!_recentlyLoadedScripts.isEmpty()); + + int limit = _recentlyLoadedScripts.size() > 9 ? 9 : _recentlyLoadedScripts.size(); + ui->recentlyLoadedScriptsTableWidget->setRowCount(limit); + for (int i = 0; i < limit; ++i) { + QTableWidgetItem *scriptName = new QTableWidgetItem; + scriptName->setText(_recentlyLoadedScripts.at(i)); + scriptName->setToolTip(_recentlyLoadedScripts.at(i)); + scriptName->setTextAlignment(Qt::AlignCenter); + QTableWidgetItem *number = new QTableWidgetItem; + number->setText(QString::number(i+1) + "."); + + ui->recentlyLoadedScriptsTableWidget->setItem(i, 0, number); + ui->recentlyLoadedScriptsTableWidget->setItem(i, 1, scriptName); + } +} diff --git a/interface/src/ui/RunningScriptsWidget.h b/interface/src/ui/RunningScriptsWidget.h new file mode 100644 index 0000000000..212980ecff --- /dev/null +++ b/interface/src/ui/RunningScriptsWidget.h @@ -0,0 +1,46 @@ +// +// RunningScripts.h +// interface +// +// Created by Mohammed Nafees on 03/28/2014. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. + +#ifndef __hifi__RunningScriptsWidget__ +#define __hifi__RunningScriptsWidget__ + +// Qt +#include + +namespace Ui { + class RunningScriptsWidget; +} + +class RunningScriptsWidget : public QDockWidget +{ + Q_OBJECT +public: + explicit RunningScriptsWidget(QDockWidget *parent = 0); + ~RunningScriptsWidget(); + + void setRunningScripts(const QStringList& list); + +signals: + void stopScriptName(QString name); + +protected: + void keyPressEvent(QKeyEvent *e); + +private slots: + void stopScript(int row, int column); + void loadScript(int row, int column); + void allScriptsStopped(); + +private: + Ui::RunningScriptsWidget *ui; + QStringList _recentlyLoadedScripts; + QString _lastStoppedScript; + + void createRecentlyLoadedScriptsTable(); +}; + +#endif /* defined(__hifi__RunningScriptsWidget__) */ diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui new file mode 100644 index 0000000000..9494d4ed09 --- /dev/null +++ b/interface/ui/runningScriptsWidget.ui @@ -0,0 +1,248 @@ + + + RunningScriptsWidget + + + + 0 + 0 + 310 + 651 + + + + Form + + + background: #f7f7f7; +font-family: Helvetica, Arial, "DejaVu Sans"; + + + + + 20 + 10 + 221 + 31 + + + + color: #0e7077; + + + <html><head/><body><p><span style=" font-size:18pt;">Running Scripts</span></p></body></html> + + + + + + 20 + 40 + 301 + 20 + + + + color: #0e7077; + + + <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> + + + + + + 40 + 230 + 111 + 31 + + + + PointingHandCursor + + + background: #0e7077; +color: #fff; +border-radius: 6px; + + + Reload All + + + + :/images/reload.svg:/images/reload.svg + + + + + + 160 + 230 + 101 + 31 + + + + PointingHandCursor + + + background: #0e7077; +color: #fff; +border-radius: 6px; + + + Stop All + + + + :/images/stop.svg:/images/stop.svg + + + + + + 20 + 280 + 301 + 20 + + + + color: #0e7077; + + + <html><head/><body><p><span style=" font-weight:600;">Recently loaded</span></p></body></html> + + + + + + 20 + 300 + 271 + 8 + + + + + + + Qt::Horizontal + + + + + + 20 + 590 + 271 + 41 + + + + color: #95a5a6; + + + (click a script or use the 1-9 keys to load and run it) + + + true + + + + + + 270 + 10 + 31 + 31 + + + + PointingHandCursor + + + + + + + :/images/close.svg:/images/close.svg + + + + 20 + 20 + + + + true + + + + + + 20 + 70 + 271 + 141 + + + + background: transparent; + + + + + + 20 + 60 + 271 + 8 + + + + + + + Qt::Horizontal + + + + + + 20 + 310 + 271 + 281 + + + + background: transparent; + + + + + + 20 + 40 + 271 + 51 + + + + font: 14px; + + + There are no scripts currently running. + + + Qt::AlignCenter + + + + + + + + diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 1f1eab6baf..7572638a30 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -29,7 +29,6 @@ #include "LocalVoxels.h" #include "ScriptEngine.h" -int ScriptEngine::_scriptNumber = 1; VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface; ParticlesScriptingInterface ScriptEngine::_particlesScriptingInterface; @@ -41,7 +40,7 @@ static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* eng } -ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, const QString& fileNameString, +ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, AbstractControllerScriptingInterface* controllerScriptingInterface) : _scriptContents(scriptContents), @@ -58,26 +57,15 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, co _numAvatarSoundSentBytes(0), _controllerScriptingInterface(controllerScriptingInterface), _avatarData(NULL), - _wantMenuItems(wantMenuItems), - _scriptMenuName(), + _scriptName(), _fileNameString(fileNameString), _quatLibrary(), _vec3Library() { - // some clients will use these menu features - if (!fileNameString.isEmpty()) { - _scriptMenuName = "Stop "; - _scriptMenuName.append(qPrintable(fileNameString)); - _scriptMenuName.append(QString(" [%1]").arg(_scriptNumber)); - } else { - _scriptMenuName = "Stop Script "; - _scriptMenuName.append(_scriptNumber); - } - _scriptNumber++; } -ScriptEngine::ScriptEngine(const QUrl& scriptURL, bool wantMenuItems, - AbstractControllerScriptingInterface* controllerScriptingInterface) : +ScriptEngine::ScriptEngine(const QUrl& scriptURL, + AbstractControllerScriptingInterface* controllerScriptingInterface) : _scriptContents(), _isFinished(false), _isRunning(false), @@ -92,32 +80,21 @@ ScriptEngine::ScriptEngine(const QUrl& scriptURL, bool wantMenuItems, _numAvatarSoundSentBytes(0), _controllerScriptingInterface(controllerScriptingInterface), _avatarData(NULL), - _wantMenuItems(wantMenuItems), - _scriptMenuName(), + _scriptName(), _fileNameString(), _quatLibrary(), _vec3Library() { QString scriptURLString = scriptURL.toString(); _fileNameString = scriptURLString; - // some clients will use these menu features - if (!scriptURLString.isEmpty()) { - _scriptMenuName = "Stop "; - _scriptMenuName.append(qPrintable(scriptURLString)); - _scriptMenuName.append(QString(" [%1]").arg(_scriptNumber)); - } else { - _scriptMenuName = "Stop Script "; - _scriptMenuName.append(_scriptNumber); - } - _scriptNumber++; - + QUrl url(scriptURL); - + // if the scheme is empty, maybe they typed in a file, let's try if (url.scheme().isEmpty()) { url = QUrl::fromLocalFile(scriptURLString); } - + // ok, let's see if it's valid... and if so, load it if (url.isValid()) { if (url.scheme() == "file") { @@ -144,16 +121,16 @@ ScriptEngine::ScriptEngine(const QUrl& scriptURL, bool wantMenuItems, void ScriptEngine::setIsAvatar(bool isAvatar) { _isAvatar = isAvatar; - + if (_isAvatar && !_avatarIdentityTimer) { // set up the avatar timers _avatarIdentityTimer = new QTimer(this); _avatarBillboardTimer = new QTimer(this); - + // connect our slot connect(_avatarIdentityTimer, &QTimer::timeout, this, &ScriptEngine::sendAvatarIdentityPacket); connect(_avatarBillboardTimer, &QTimer::timeout, this, &ScriptEngine::sendAvatarBillboardPacket); - + // start the timers _avatarIdentityTimer->start(AVATAR_IDENTITY_PACKET_SEND_INTERVAL_MSECS); _avatarBillboardTimer->start(AVATAR_BILLBOARD_PACKET_SEND_INTERVAL_MSECS); @@ -162,20 +139,14 @@ void ScriptEngine::setIsAvatar(bool isAvatar) { void ScriptEngine::setAvatarData(AvatarData* avatarData, const QString& objectName) { _avatarData = avatarData; - + // remove the old Avatar property, if it exists _engine.globalObject().setProperty(objectName, QScriptValue()); - + // give the script engine the new Avatar script property registerGlobalObject(objectName, _avatarData); } -void ScriptEngine::cleanupMenuItems() { - if (_wantMenuItems) { - emit cleanupMenuItem(_scriptMenuName); - } -} - bool ScriptEngine::setScriptContents(const QString& scriptContents, const QString& fileNameString) { if (_isRunning) { return false; @@ -203,7 +174,7 @@ void ScriptEngine::init() { registerVoxelMetaTypes(&_engine); registerEventTypes(&_engine); registerMenuItemProperties(&_engine); - + qScriptRegisterMetaType(&_engine, ParticlePropertiesToScriptValue, ParticlePropertiesFromScriptValue); qScriptRegisterMetaType(&_engine, ParticleIDtoScriptValue, ParticleIDfromScriptValue); qScriptRegisterSequenceMetaType >(&_engine); @@ -216,7 +187,7 @@ void ScriptEngine::init() { QScriptValue injectionOptionValue = _engine.scriptValueFromQMetaObject(); _engine.globalObject().setProperty("AudioInjectionOptions", injectionOptionValue); - + QScriptValue localVoxelsValue = _engine.scriptValueFromQMetaObject(); _engine.globalObject().setProperty("LocalVoxels", localVoxelsValue); @@ -285,9 +256,9 @@ void ScriptEngine::run() { gettimeofday(&startTime, NULL); int thisFrame = 0; - + NodeList* nodeList = NodeList::getInstance(); - + qint64 lastUpdate = usecTimestampNow(); while (!_isFinished) { @@ -325,36 +296,36 @@ void ScriptEngine::run() { _particlesScriptingInterface.getParticlePacketSender()->process(); } } - + if (_isAvatar && _avatarData) { - + const int SCRIPT_AUDIO_BUFFER_SAMPLES = floor(((SCRIPT_DATA_CALLBACK_USECS * SAMPLE_RATE) / (1000 * 1000)) + 0.5); const int SCRIPT_AUDIO_BUFFER_BYTES = SCRIPT_AUDIO_BUFFER_SAMPLES * sizeof(int16_t); - + QByteArray avatarPacket = byteArrayWithPopulatedHeader(PacketTypeAvatarData); avatarPacket.append(_avatarData->toByteArray()); - + nodeList->broadcastToNodes(avatarPacket, NodeSet() << NodeType::AvatarMixer); - + if (_isListeningToAudioStream || _avatarSound) { // if we have an avatar audio stream then send it out to our audio-mixer bool silentFrame = true; - + int16_t numAvailableSamples = SCRIPT_AUDIO_BUFFER_SAMPLES; const int16_t* nextSoundOutput = NULL; - + if (_avatarSound) { - + const QByteArray& soundByteArray = _avatarSound->getByteArray(); nextSoundOutput = reinterpret_cast(soundByteArray.data() + _numAvatarSoundSentBytes); - + int numAvailableBytes = (soundByteArray.size() - _numAvatarSoundSentBytes) > SCRIPT_AUDIO_BUFFER_BYTES ? SCRIPT_AUDIO_BUFFER_BYTES : soundByteArray.size() - _numAvatarSoundSentBytes; numAvailableSamples = numAvailableBytes / sizeof(int16_t); - - + + // check if the all of the _numAvatarAudioBufferSamples to be sent are silence for (int i = 0; i < numAvailableSamples; ++i) { if (nextSoundOutput[i] != 0) { @@ -362,7 +333,7 @@ void ScriptEngine::run() { break; } } - + _numAvatarSoundSentBytes += numAvailableBytes; if (_numAvatarSoundSentBytes == soundByteArray.size()) { // we're done with this sound object - so set our pointer back to NULL @@ -371,24 +342,24 @@ void ScriptEngine::run() { _numAvatarSoundSentBytes = 0; } } - + QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame ? PacketTypeSilentAudioFrame : PacketTypeMicrophoneAudioNoEcho); - + QDataStream packetStream(&audioPacket, QIODevice::Append); - + // use the orientation and position of this avatar for the source of this audio packetStream.writeRawData(reinterpret_cast(&_avatarData->getPosition()), sizeof(glm::vec3)); glm::quat headOrientation = _avatarData->getHeadOrientation(); packetStream.writeRawData(reinterpret_cast(&headOrientation), sizeof(glm::quat)); - + if (silentFrame) { if (!_isListeningToAudioStream) { // if we have a silent frame and we're not listening then just send nothing and break out of here break; } - + // write the number of silent samples so the audio-mixer can uphold timing packetStream.writeRawData(reinterpret_cast(&SCRIPT_AUDIO_BUFFER_SAMPLES), sizeof(int16_t)); } else if (nextSoundOutput) { @@ -396,7 +367,7 @@ void ScriptEngine::run() { packetStream.writeRawData(reinterpret_cast(nextSoundOutput), numAvailableSamples * sizeof(int16_t)); } - + nodeList->broadcastToNodes(audioPacket, NodeSet() << NodeType::AudioMixer); } } @@ -412,10 +383,10 @@ void ScriptEngine::run() { } } emit scriptEnding(); - + // kill the avatar identity timer delete _avatarIdentityTimer; - + if (_voxelsScriptingInterface.getVoxelPacketSender()->serversExist()) { // release the queue of edit voxel messages. _voxelsScriptingInterface.getVoxelPacketSender()->releaseQueuedMessages(); @@ -435,8 +406,6 @@ void ScriptEngine::run() { _particlesScriptingInterface.getParticlePacketSender()->process(); } } - - cleanupMenuItems(); // If we were on a thread, then wait till it's done if (thread()) { @@ -444,7 +413,7 @@ void ScriptEngine::run() { } emit finished(_fileNameString); - + _isRunning = false; } @@ -454,13 +423,13 @@ void ScriptEngine::stop() { void ScriptEngine::timerFired() { QTimer* callingTimer = reinterpret_cast(sender()); - + // call the associated JS function, if it exists QScriptValue timerFunction = _timerFunctionMap.value(callingTimer); if (timerFunction.isValid()) { timerFunction.call(); } - + if (!callingTimer->isActive()) { // this timer is done, we can kill it delete callingTimer; @@ -471,14 +440,14 @@ QObject* ScriptEngine::setupTimerWithInterval(const QScriptValue& function, int // create the timer, add it to the map, and start it QTimer* newTimer = new QTimer(this); newTimer->setSingleShot(isSingleShot); - + connect(newTimer, &QTimer::timeout, this, &ScriptEngine::timerFired); - + // make sure the timer stops when the script does connect(this, &ScriptEngine::scriptEnding, newTimer, &QTimer::stop); - + _timerFunctionMap.insert(newTimer, function); - + newTimer->start(intervalMS); return newTimer; } @@ -505,17 +474,17 @@ QUrl ScriptEngine::resolveInclude(const QString& include) const { if (!url.scheme().isEmpty()) { return url; } - - // we apparently weren't a fully qualified url, so, let's assume we're relative + + // we apparently weren't a fully qualified url, so, let's assume we're relative // to the original URL of our script QUrl parentURL(_fileNameString); - + // if the parent URL's scheme is empty, then this is probably a local file... if (parentURL.scheme().isEmpty()) { parentURL = QUrl::fromLocalFile(_fileNameString); } - - // at this point we should have a legitimate fully qualified URL for our parent + + // at this point we should have a legitimate fully qualified URL for our parent url = parentURL.resolved(url); return url; } @@ -543,7 +512,7 @@ void ScriptEngine::include(const QString& includeFile) { loop.exec(); includeContents = reply->readAll(); } - + QScriptValue result = _engine.evaluate(includeContents); if (_engine.hasUncaughtException()) { int line = _engine.uncaughtExceptionLineNumber(); diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 4fc90d2959..964f64a005 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -33,11 +33,11 @@ const unsigned int SCRIPT_DATA_CALLBACK_USECS = floor(((1.0 / 60.0f) * 1000 * 10 class ScriptEngine : public QObject { Q_OBJECT public: - ScriptEngine(const QUrl& scriptURL, bool wantMenuItems = false, + ScriptEngine(const QUrl& scriptURL, AbstractControllerScriptingInterface* controllerScriptingInterface = NULL); - ScriptEngine(const QString& scriptContents = NO_SCRIPT, bool wantMenuItems = false, - const QString& fileNameString = QString(""), + ScriptEngine(const QString& scriptContents = NO_SCRIPT, + const QString& fileNameString = QString(""), AbstractControllerScriptingInterface* controllerScriptingInterface = NULL); /// Access the VoxelsScriptingInterface in order to initialize it with a custom packet sender and jurisdiction listener @@ -49,39 +49,39 @@ public: /// sets the script contents, will return false if failed, will fail if script is already running bool setScriptContents(const QString& scriptContents, const QString& fileNameString = QString("")); - const QString& getScriptMenuName() const { return _scriptMenuName; } + const QString& getScriptName() const { return _scriptName; } void cleanupMenuItems(); void registerGlobalObject(const QString& name, QObject* object); /// registers a global object by name - + Q_INVOKABLE void setIsAvatar(bool isAvatar); bool isAvatar() const { return _isAvatar; } - + void setAvatarData(AvatarData* avatarData, const QString& objectName); - + bool isListeningToAudioStream() const { return _isListeningToAudioStream; } void setIsListeningToAudioStream(bool isListeningToAudioStream) { _isListeningToAudioStream = isListeningToAudioStream; } - + void setAvatarSound(Sound* avatarSound) { _avatarSound = avatarSound; } bool isPlayingAvatarSound() const { return _avatarSound != NULL; } - + void init(); void run(); /// runs continuously until Agent.stop() is called void evaluate(); /// initializes the engine, and evaluates the script, but then returns control to caller - + void timerFired(); bool hasScript() const { return !_scriptContents.isEmpty(); } public slots: void stop(); - + QObject* setInterval(const QScriptValue& function, int intervalMS); QObject* setTimeout(const QScriptValue& function, int timeoutMS); void clearInterval(QObject* timer) { stopTimer(reinterpret_cast(timer)); } void clearTimeout(QObject* timer) { stopTimer(reinterpret_cast(timer)); } void include(const QString& includeFile); - + signals: void update(float deltaTime); void scriptEnding(); @@ -106,19 +106,18 @@ private: QUrl resolveInclude(const QString& include) const; void sendAvatarIdentityPacket(); void sendAvatarBillboardPacket(); - + QObject* setupTimerWithInterval(const QScriptValue& function, int intervalMS, bool isSingleShot); void stopTimer(QTimer* timer); - + static VoxelsScriptingInterface _voxelsScriptingInterface; static ParticlesScriptingInterface _particlesScriptingInterface; static int _scriptNumber; - + AbstractControllerScriptingInterface* _controllerScriptingInterface; AudioScriptingInterface _audioScriptingInterface; AvatarData* _avatarData; - bool _wantMenuItems; - QString _scriptMenuName; + QString _scriptName; QString _fileNameString; Quat _quatLibrary; Vec3 _vec3Library; From c358c6ff99c47a27b499875aa6c2ff22a1a153fa Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Wed, 2 Apr 2014 15:55:47 +0530 Subject: [PATCH 02/37] fixed signal parameter --- interface/src/ui/RunningScriptsWidget.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/RunningScriptsWidget.h b/interface/src/ui/RunningScriptsWidget.h index 212980ecff..d92927347f 100644 --- a/interface/src/ui/RunningScriptsWidget.h +++ b/interface/src/ui/RunningScriptsWidget.h @@ -25,7 +25,7 @@ public: void setRunningScripts(const QStringList& list); signals: - void stopScriptName(QString name); + void stopScriptName(const QString& name); protected: void keyPressEvent(QKeyEvent *e); From 0fa910c61fd4ffb4e4eb4b7c53f1e67da9ac0913 Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Wed, 2 Apr 2014 16:16:23 +0530 Subject: [PATCH 03/37] fix ubuntu build error --- interface/src/Application.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index d6783fe78d..221a81478e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -500,7 +500,7 @@ private: Overlays _overlays; - QPointer _runningScriptsWidget; + RunningScriptsWidget* _runningScriptsWidget; QHash _scriptEnginesHash; }; From e5d9812742fe7a9295c1b20bf0a302ee1b285793 Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Thu, 3 Apr 2014 13:21:27 +0530 Subject: [PATCH 04/37] Major changes to the running scripts widget --- interface/interface_en.ts | 30 +++--- interface/src/ui/RunningScriptsWidget.cpp | 92 +++++++++++------- interface/src/ui/RunningScriptsWidget.h | 10 +- interface/src/ui/ScriptsTableWidget.cpp | 41 ++++++++ interface/src/ui/ScriptsTableWidget.h | 23 +++++ interface/ui/runningScriptsWidget.ui | 111 +++++++++------------- 6 files changed, 188 insertions(+), 119 deletions(-) create mode 100644 interface/src/ui/ScriptsTableWidget.cpp create mode 100644 interface/src/ui/ScriptsTableWidget.h diff --git a/interface/interface_en.ts b/interface/interface_en.ts index c924e76330..3446903bb3 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -162,49 +162,49 @@ RunningScriptsWidget - + Form - - + + <html><head/><body><p><span style=" font-size:18pt;">Running Scripts</span></p></body></html> - - + + <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> - - + + Reload All - - + + Stop All - - + + <html><head/><body><p><span style=" font-weight:600;">Recently loaded</span></p></body></html> - - + + (click a script or use the 1-9 keys to load and run it) - - + + There are no scripts currently running. diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 2238cab2df..66664dcc8c 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -1,5 +1,5 @@ // -// RunningScripts.cpp +// RunningScriptsWidget.cpp // interface // // Created by Mohammed Nafees on 03/28/2014. @@ -9,6 +9,8 @@ #include "RunningScriptsWidget.h" #include +#include +#include #include #include "Application.h" @@ -22,25 +24,17 @@ RunningScriptsWidget::RunningScriptsWidget(QDockWidget *parent) : // remove the title bar (see the Qt docs on setTitleBarWidget) setTitleBarWidget(new QWidget()); - ui->runningScriptsTableWidget->setColumnCount(2); - ui->runningScriptsTableWidget->verticalHeader()->setVisible(false); - ui->runningScriptsTableWidget->horizontalHeader()->setVisible(false); - ui->runningScriptsTableWidget->setSelectionMode(QAbstractItemView::NoSelection); - ui->runningScriptsTableWidget->setShowGrid(false); - ui->runningScriptsTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); - ui->runningScriptsTableWidget->setColumnWidth(0, 235); - ui->runningScriptsTableWidget->setColumnWidth(1, 25); - connect(ui->runningScriptsTableWidget, &QTableWidget::cellClicked, this, &RunningScriptsWidget::stopScript); + _runningScriptsTable = new ScriptsTableWidget(ui->runningScriptsTableWidget); + _runningScriptsTable->setColumnCount(2); + _runningScriptsTable->setColumnWidth(0, 245); + _runningScriptsTable->setColumnWidth(1, 22); + connect(_runningScriptsTable, &QTableWidget::cellClicked, this, &RunningScriptsWidget::stopScript); - ui->recentlyLoadedScriptsTableWidget->setColumnCount(2); - ui->recentlyLoadedScriptsTableWidget->verticalHeader()->setVisible(false); - ui->recentlyLoadedScriptsTableWidget->horizontalHeader()->setVisible(false); - ui->recentlyLoadedScriptsTableWidget->setSelectionMode(QAbstractItemView::NoSelection); - ui->recentlyLoadedScriptsTableWidget->setShowGrid(false); - ui->recentlyLoadedScriptsTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); - ui->recentlyLoadedScriptsTableWidget->setColumnWidth(0, 25); - ui->recentlyLoadedScriptsTableWidget->setColumnWidth(1, 235); - connect(ui->recentlyLoadedScriptsTableWidget, &QTableWidget::cellClicked, + _recentlyLoadedScriptsTable = new ScriptsTableWidget(ui->recentlyLoadedScriptsTableWidget); + _recentlyLoadedScriptsTable->setColumnCount(2); + _recentlyLoadedScriptsTable->setColumnWidth(0, 25); + _recentlyLoadedScriptsTable->setColumnWidth(1, 235); + connect(_recentlyLoadedScriptsTable, &QTableWidget::cellClicked, this, &RunningScriptsWidget::loadScript); connect(ui->hideWidgetButton, &QPushButton::clicked, @@ -58,25 +52,24 @@ RunningScriptsWidget::~RunningScriptsWidget() void RunningScriptsWidget::setRunningScripts(const QStringList& list) { - ui->runningScriptsTableWidget->setRowCount(list.size()); + _runningScriptsTable->setRowCount(list.size()); ui->noRunningScriptsLabel->setVisible(list.isEmpty()); ui->currentlyRunningLabel->setVisible(!list.isEmpty()); - ui->line1->setVisible(!list.isEmpty()); ui->runningScriptsTableWidget->setVisible(!list.isEmpty()); ui->reloadAllButton->setVisible(!list.isEmpty()); ui->stopAllButton->setVisible(!list.isEmpty()); for (int i = 0; i < list.size(); ++i) { QTableWidgetItem *scriptName = new QTableWidgetItem; - scriptName->setText(list.at(i)); + scriptName->setText(QFileInfo(list.at(i)).fileName()); scriptName->setToolTip(list.at(i)); - scriptName->setTextAlignment(Qt::AlignCenter); + scriptName->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); QTableWidgetItem *closeIcon = new QTableWidgetItem; - closeIcon->setIcon(QIcon(":/images/kill-script.svg")); + closeIcon->setIcon(QIcon(QPixmap(":/images/kill-script.svg").scaledToHeight(12))); - ui->runningScriptsTableWidget->setItem(i, 0, scriptName); - ui->runningScriptsTableWidget->setItem(i, 1, closeIcon); + _runningScriptsTable->setItem(i, 0, scriptName); + _runningScriptsTable->setItem(i, 1, closeIcon); } createRecentlyLoadedScriptsTable(); @@ -146,17 +139,37 @@ void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) } } +void RunningScriptsWidget::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setPen(QColor::fromRgb(196, 196, 196)); + + if (ui->currentlyRunningLabel->isVisible()) { + // line below the 'Currently Running' label + painter.drawLine(20, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height(), + width() - 20, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height()); + } + + if (ui->recentlyLoadedLabel->isVisible()) { + // line below the 'Recently loaded' label + painter.drawLine(20, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height(), + width() - 20, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height()); + } + + painter.end(); +} + void RunningScriptsWidget::stopScript(int row, int column) { if (column == 1) { // make sure the user has clicked on the close icon - _lastStoppedScript = ui->runningScriptsTableWidget->item(row, 0)->text(); - emit stopScriptName(ui->runningScriptsTableWidget->item(row, 0)->text()); + _lastStoppedScript = _runningScriptsTable->item(row, 0)->toolTip(); + emit stopScriptName(_runningScriptsTable->item(row, 0)->toolTip()); } } void RunningScriptsWidget::loadScript(int row, int column) { - Application::getInstance()->loadScript(ui->recentlyLoadedScriptsTableWidget->item(row, column)->text()); + Application::getInstance()->loadScript(_recentlyLoadedScriptsTable->item(row, column)->toolTip()); } void RunningScriptsWidget::allScriptsStopped() @@ -183,21 +196,30 @@ void RunningScriptsWidget::createRecentlyLoadedScriptsTable() } ui->recentlyLoadedLabel->setVisible(!_recentlyLoadedScripts.isEmpty()); - ui->line2->setVisible(!_recentlyLoadedScripts.isEmpty()); ui->recentlyLoadedScriptsTableWidget->setVisible(!_recentlyLoadedScripts.isEmpty()); ui->recentlyLoadedInstruction->setVisible(!_recentlyLoadedScripts.isEmpty()); int limit = _recentlyLoadedScripts.size() > 9 ? 9 : _recentlyLoadedScripts.size(); - ui->recentlyLoadedScriptsTableWidget->setRowCount(limit); + _recentlyLoadedScriptsTable->setRowCount(limit); for (int i = 0; i < limit; ++i) { QTableWidgetItem *scriptName = new QTableWidgetItem; - scriptName->setText(_recentlyLoadedScripts.at(i)); + scriptName->setText(QFileInfo(_recentlyLoadedScripts.at(i)).fileName()); scriptName->setToolTip(_recentlyLoadedScripts.at(i)); - scriptName->setTextAlignment(Qt::AlignCenter); + scriptName->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); QTableWidgetItem *number = new QTableWidgetItem; number->setText(QString::number(i+1) + "."); + number->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); - ui->recentlyLoadedScriptsTableWidget->setItem(i, 0, number); - ui->recentlyLoadedScriptsTableWidget->setItem(i, 1, scriptName); + _recentlyLoadedScriptsTable->setItem(i, 0, number); + _recentlyLoadedScriptsTable->setItem(i, 1, scriptName); } + + int y = ui->recentlyLoadedScriptsTableWidget->y() + 15; + for (int i = 0; i < _recentlyLoadedScriptsTable->rowCount(); ++i) { + y += _recentlyLoadedScriptsTable->rowHeight(i); + } + + ui->recentlyLoadedInstruction->setGeometry(20, y, width() - 20, ui->recentlyLoadedInstruction->height()); + + repaint(); } diff --git a/interface/src/ui/RunningScriptsWidget.h b/interface/src/ui/RunningScriptsWidget.h index d92927347f..51c19028cd 100644 --- a/interface/src/ui/RunningScriptsWidget.h +++ b/interface/src/ui/RunningScriptsWidget.h @@ -1,5 +1,5 @@ // -// RunningScripts.h +// RunningScriptsWidget.h // interface // // Created by Mohammed Nafees on 03/28/2014. @@ -8,9 +8,10 @@ #ifndef __hifi__RunningScriptsWidget__ #define __hifi__RunningScriptsWidget__ -// Qt #include +#include "ScriptsTableWidget.h" + namespace Ui { class RunningScriptsWidget; } @@ -28,7 +29,8 @@ signals: void stopScriptName(const QString& name); protected: - void keyPressEvent(QKeyEvent *e); + virtual void keyPressEvent(QKeyEvent *e); + virtual void paintEvent(QPaintEvent *); private slots: void stopScript(int row, int column); @@ -37,6 +39,8 @@ private slots: private: Ui::RunningScriptsWidget *ui; + ScriptsTableWidget *_runningScriptsTable; + ScriptsTableWidget *_recentlyLoadedScriptsTable; QStringList _recentlyLoadedScripts; QString _lastStoppedScript; diff --git a/interface/src/ui/ScriptsTableWidget.cpp b/interface/src/ui/ScriptsTableWidget.cpp new file mode 100644 index 0000000000..e954500022 --- /dev/null +++ b/interface/src/ui/ScriptsTableWidget.cpp @@ -0,0 +1,41 @@ +// +// ScriptsTableWidget.cpp +// interface +// +// Created by Mohammed Nafees on 04/03/2014. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. + +#include "ScriptsTableWidget.h" + +#include +#include +#include +#include +#include + +ScriptsTableWidget::ScriptsTableWidget(QWidget *parent) : + QTableWidget(parent) +{ + verticalHeader()->setVisible(false); + horizontalHeader()->setVisible(false); + setShowGrid(false); + setSelectionMode(QAbstractItemView::NoSelection); + setEditTriggers(QAbstractItemView::NoEditTriggers); + setStyleSheet("background: transparent;"); + setGeometry(0, 0, parent->width(), parent->height()); +} + +void ScriptsTableWidget::paintEvent(QPaintEvent *event) +{ + QPainter painter(viewport()); + painter.setPen(QColor::fromRgb(196, 196, 196)); + + int y = 0; + for (int i = 0; i < rowCount(); ++i) { + painter.drawLine(0, rowHeight(i) + y, width(), rowHeight(i) + y); + y += rowHeight(i); + } + painter.end(); + + QTableWidget::paintEvent(event); +} diff --git a/interface/src/ui/ScriptsTableWidget.h b/interface/src/ui/ScriptsTableWidget.h new file mode 100644 index 0000000000..f4726ab26d --- /dev/null +++ b/interface/src/ui/ScriptsTableWidget.h @@ -0,0 +1,23 @@ +// +// ScriptsTableWidget.h +// interface +// +// Created by Mohammed Nafees on 04/03/2014. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. + +#ifndef __hifi__ScriptsTableWidget__ +#define __hifi__ScriptsTableWidget__ + +#include + +class ScriptsTableWidget : public QTableWidget +{ + Q_OBJECT +public: + explicit ScriptsTableWidget(QWidget *parent); + +protected: + virtual void paintEvent(QPaintEvent *event); +}; + +#endif /* defined(__hifi__ScriptsTableWidget__) */ diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index 9494d4ed09..d35caf0d77 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -27,7 +27,8 @@ font-family: Helvetica, Arial, "DejaVu Sans"; - color: #0e7077; + color: #0e7077; +font-size: 20pt; <html><head/><body><p><span style=" font-size:18pt;">Running Scripts</span></p></body></html> @@ -43,7 +44,8 @@ font-family: Helvetica, Arial, "DejaVu Sans"; - color: #0e7077; + color: #0e7077; +font-size: 14pt; <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> @@ -61,10 +63,14 @@ font-family: Helvetica, Arial, "DejaVu Sans"; PointingHandCursor + + false + background: #0e7077; color: #fff; -border-radius: 6px; +border-radius: 6px; +font: 14pt 75pt; Reload All @@ -89,7 +95,8 @@ border-radius: 6px; background: #0e7077; color: #fff; -border-radius: 6px; +border-radius: 6px; +font: 14pt 75pt; Stop All @@ -109,28 +116,13 @@ border-radius: 6px; - color: #0e7077; + color: #0e7077; +font-size: 14pt; <html><head/><body><p><span style=" font-weight:600;">Recently loaded</span></p></body></html> - - - - 20 - 300 - 271 - 8 - - - - - - - Qt::Horizontal - - @@ -141,7 +133,8 @@ border-radius: 6px; - color: #95a5a6; + color: #95a5a6; +font-size: 14pt; (click a script or use the 1-9 keys to load and run it) @@ -179,59 +172,17 @@ border-radius: 6px; true - - - - 20 - 70 - 271 - 141 - - - - background: transparent; - - - + 20 60 271 - 8 - - - - - - - Qt::Horizontal - - - - - - 20 - 310 - 271 - 281 - - - - background: transparent; - - - - - - 20 - 40 - 271 51 - font: 14px; + font: 14pt; There are no scripts currently running. @@ -240,6 +191,34 @@ border-radius: 6px; Qt::AlignCenter + + + + 20 + 300 + 270 + 280 + + + + background: transparent; +font-size: 14pt; + + + + + + 20 + 60 + 270 + 140 + + + + background: transparent; +font-size: 14pt; + + From 2ef8277d0f3ea367c3ee9825a81c60d001b950bd Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Thu, 3 Apr 2014 18:04:26 +0530 Subject: [PATCH 05/37] Make the widget move and resize along with the main window --- interface/interface_en.ts | 8 ++++---- interface/src/Application.cpp | 7 +++++++ interface/src/Application.h | 1 + interface/src/ui/ScriptsTableWidget.cpp | 2 -- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index 3446903bb3..92ccb01cb4 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) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index aae1a227a1..a63cbffd31 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -619,6 +619,11 @@ void Application::resizeGL(int width, int height) { updateProjectionMatrix(); glLoadIdentity(); + + if (_runningScriptsWidgetVisible) + _runningScriptsWidget->setGeometry(_window->geometry().topLeft().x(), + _window->geometry().topLeft().y(), + _runningScriptsWidget->width(), _window->height()); } void Application::updateProjectionMatrix() { @@ -3629,6 +3634,7 @@ void Application::toggleRunningScriptsWidget() _runningScriptsWidget->resize(0, _window->height()); _runningScriptsWidget->toggleViewAction()->trigger(); _runningScriptsWidget->grabKeyboard(); + _runningScriptsWidgetVisible = true; QPropertyAnimation* slideAnimation = new QPropertyAnimation(_runningScriptsWidget, "geometry", _runningScriptsWidget); slideAnimation->setStartValue(_runningScriptsWidget->geometry()); @@ -3638,6 +3644,7 @@ void Application::toggleRunningScriptsWidget() slideAnimation->start(QAbstractAnimation::DeleteWhenStopped); } else { _runningScriptsWidget->releaseKeyboard(); + _runningScriptsWidgetVisible = false; QPropertyAnimation* slideAnimation = new QPropertyAnimation(_runningScriptsWidget, "geometry", _runningScriptsWidget); slideAnimation->setStartValue(_runningScriptsWidget->geometry()); diff --git a/interface/src/Application.h b/interface/src/Application.h index 221a81478e..32e8d3ac62 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -502,6 +502,7 @@ private: RunningScriptsWidget* _runningScriptsWidget; QHash _scriptEnginesHash; + bool _runningScriptsWidgetVisible; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/ui/ScriptsTableWidget.cpp b/interface/src/ui/ScriptsTableWidget.cpp index e954500022..af67b939eb 100644 --- a/interface/src/ui/ScriptsTableWidget.cpp +++ b/interface/src/ui/ScriptsTableWidget.cpp @@ -8,9 +8,7 @@ #include "ScriptsTableWidget.h" #include -#include #include -#include #include ScriptsTableWidget::ScriptsTableWidget(QWidget *parent) : From f3121e1bf6c6ec1c8de029266f49c29e15637554 Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Thu, 3 Apr 2014 22:33:45 +0530 Subject: [PATCH 06/37] Removed the animation, placed UI elements according to mockup --- interface/interface_en.ts | 30 ++++++++++--------- interface/src/Application.cpp | 35 ++++++++--------------- interface/src/Application.h | 1 - interface/src/ui/RunningScriptsWidget.cpp | 9 +++--- interface/ui/runningScriptsWidget.ui | 29 ++++++++++--------- 5 files changed, 48 insertions(+), 56 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index 92ccb01cb4..16de312c33 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) @@ -162,49 +162,51 @@ RunningScriptsWidget - + Form - + <html><head/><body><p><span style=" font-size:18pt;">Running Scripts</span></p></body></html> - + <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> - - Reload All + + Reload all + Reload All - - Stop All + + Stop all + Stop All - + <html><head/><body><p><span style=" font-weight:600;">Recently loaded</span></p></body></html> - + (click a script or use the 1-9 keys to load and run it) - + There are no scripts currently running. diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a63cbffd31..01cccbde47 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -171,7 +171,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _recentMaxPackets(0), _resetRecentMaxPacketsSoon(true), _previousScriptLocation(), - _logger(new FileLogger(this)) + _logger(new FileLogger(this)), + _runningScriptsWidget(new RunningScriptsWidget) { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -333,7 +334,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : LocalVoxelsList::getInstance()->addPersistantTree(DOMAIN_TREE_NAME, _voxels.getTree()); LocalVoxelsList::getInstance()->addPersistantTree(CLIPBOARD_TREE_NAME, &_clipboard); - _window->addDockWidget(Qt::NoDockWidgetArea, _runningScriptsWidget = new RunningScriptsWidget()); + _window->addDockWidget(Qt::NoDockWidgetArea, _runningScriptsWidget); + _runningScriptsWidget->hide(); _runningScriptsWidget->setRunningScripts(getRunningScripts()); connect(_runningScriptsWidget, &RunningScriptsWidget::stopScriptName, this, &Application::stopScript); @@ -620,10 +622,11 @@ void Application::resizeGL(int width, int height) { updateProjectionMatrix(); glLoadIdentity(); - if (_runningScriptsWidgetVisible) + if (_runningScriptsWidget->isVisible()) { _runningScriptsWidget->setGeometry(_window->geometry().topLeft().x(), _window->geometry().topLeft().y(), _runningScriptsWidget->width(), _window->height()); + } } void Application::updateProjectionMatrix() { @@ -3630,30 +3633,16 @@ void Application::reloadAllScripts() { void Application::toggleRunningScriptsWidget() { if (!_runningScriptsWidget->toggleViewAction()->isChecked()) { - _runningScriptsWidget->move(_window->geometry().topLeft().x(), _window->geometry().topLeft().y()); - _runningScriptsWidget->resize(0, _window->height()); + _runningScriptsWidget->setGeometry(_window->geometry().topLeft().x(), + _window->geometry().topLeft().y(), + 310, _window->height()); _runningScriptsWidget->toggleViewAction()->trigger(); _runningScriptsWidget->grabKeyboard(); - _runningScriptsWidgetVisible = true; - - QPropertyAnimation* slideAnimation = new QPropertyAnimation(_runningScriptsWidget, "geometry", _runningScriptsWidget); - slideAnimation->setStartValue(_runningScriptsWidget->geometry()); - slideAnimation->setEndValue(QRect(_window->geometry().topLeft().x(), _window->geometry().topLeft().y(), - 310, _runningScriptsWidget->height())); - slideAnimation->setDuration(250); - slideAnimation->start(QAbstractAnimation::DeleteWhenStopped); + _runningScriptsWidget->show(); } else { + _runningScriptsWidget->toggleViewAction()->trigger(); _runningScriptsWidget->releaseKeyboard(); - _runningScriptsWidgetVisible = false; - - QPropertyAnimation* slideAnimation = new QPropertyAnimation(_runningScriptsWidget, "geometry", _runningScriptsWidget); - slideAnimation->setStartValue(_runningScriptsWidget->geometry()); - slideAnimation->setEndValue(QRect(_window->geometry().topLeft().x(), _window->geometry().topLeft().y(), - 0, _runningScriptsWidget->height())); - slideAnimation->setDuration(250); - slideAnimation->start(QAbstractAnimation::DeleteWhenStopped); - - QTimer::singleShot(260, _runningScriptsWidget->toggleViewAction(), SLOT(trigger())); + _runningScriptsWidget->hide(); } } diff --git a/interface/src/Application.h b/interface/src/Application.h index 32e8d3ac62..221a81478e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -502,7 +502,6 @@ private: RunningScriptsWidget* _runningScriptsWidget; QHash _scriptEnginesHash; - bool _runningScriptsWidgetVisible; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 66664dcc8c..a684fb4594 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -26,14 +27,14 @@ RunningScriptsWidget::RunningScriptsWidget(QDockWidget *parent) : _runningScriptsTable = new ScriptsTableWidget(ui->runningScriptsTableWidget); _runningScriptsTable->setColumnCount(2); - _runningScriptsTable->setColumnWidth(0, 245); + _runningScriptsTable->setColumnWidth(0, 252); _runningScriptsTable->setColumnWidth(1, 22); connect(_runningScriptsTable, &QTableWidget::cellClicked, this, &RunningScriptsWidget::stopScript); _recentlyLoadedScriptsTable = new ScriptsTableWidget(ui->recentlyLoadedScriptsTableWidget); _recentlyLoadedScriptsTable->setColumnCount(2); _recentlyLoadedScriptsTable->setColumnWidth(0, 25); - _recentlyLoadedScriptsTable->setColumnWidth(1, 235); + _recentlyLoadedScriptsTable->setColumnWidth(1, 242); connect(_recentlyLoadedScriptsTable, &QTableWidget::cellClicked, this, &RunningScriptsWidget::loadScript); @@ -147,13 +148,13 @@ void RunningScriptsWidget::paintEvent(QPaintEvent *) if (ui->currentlyRunningLabel->isVisible()) { // line below the 'Currently Running' label painter.drawLine(20, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height(), - width() - 20, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height()); + width() - 21, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height()); } if (ui->recentlyLoadedLabel->isVisible()) { // line below the 'Recently loaded' label painter.drawLine(20, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height(), - width() - 20, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height()); + width() - 21, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height()); } painter.end(); diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index d35caf0d77..7353c19508 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -39,7 +39,7 @@ font-size: 20pt; 20 40 - 301 + 270 20 @@ -54,10 +54,10 @@ font-size: 14pt; - 40 + 20 230 111 - 31 + 35 @@ -69,11 +69,11 @@ font-size: 14pt; background: #0e7077; color: #fff; -border-radius: 6px; +border-radius: 4px; font: 14pt 75pt; - Reload All + Reload all @@ -83,10 +83,10 @@ font: 14pt 75pt; - 160 + 144 230 101 - 31 + 35 @@ -95,11 +95,11 @@ font: 14pt 75pt; background: #0e7077; color: #fff; -border-radius: 6px; +border-radius: 4px; font: 14pt 75pt; - Stop All + Stop all @@ -194,9 +194,9 @@ font-size: 14pt; - 20 + 14 300 - 270 + 276 280 @@ -204,14 +204,15 @@ font-size: 14pt; background: transparent; font-size: 14pt; + reloadAllButton - 20 + 14 60 - 270 - 140 + 276 + 161 From 1ecdec7a5e51c03586a300ec6dc45039df71a00d Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Fri, 4 Apr 2014 19:52:37 +0530 Subject: [PATCH 07/37] Minor changes. Added a sweet tooltip :) --- interface/interface_en.ts | 30 +++++++++++------------ interface/src/ui/RunningScriptsWidget.cpp | 10 ++++---- interface/src/ui/ScriptsTableWidget.cpp | 8 +++--- interface/ui/runningScriptsWidget.ui | 25 +++++++++++++------ 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index 16de312c33..5256944949 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -162,51 +162,51 @@ RunningScriptsWidget - + Form - - + + <html><head/><body><p><span style=" font-size:18pt;">Running Scripts</span></p></body></html> - - + + <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> - - + + Reload all Reload All - - + + Stop all Stop All - - + + <html><head/><body><p><span style=" font-weight:600;">Recently loaded</span></p></body></html> - - + + (click a script or use the 1-9 keys to load and run it) - - + + There are no scripts currently running. diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index a684fb4594..f27ea9a831 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -143,18 +143,18 @@ void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) void RunningScriptsWidget::paintEvent(QPaintEvent *) { QPainter painter(this); - painter.setPen(QColor::fromRgb(196, 196, 196)); + painter.setPen(QColor::fromRgb(225, 225, 225)); if (ui->currentlyRunningLabel->isVisible()) { // line below the 'Currently Running' label - painter.drawLine(20, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height(), - width() - 21, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height()); + painter.drawLine(21, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height(), + width() - 22, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height()); } if (ui->recentlyLoadedLabel->isVisible()) { // line below the 'Recently loaded' label - painter.drawLine(20, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height(), - width() - 21, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height()); + painter.drawLine(21, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height(), + width() - 22, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height()); } painter.end(); diff --git a/interface/src/ui/ScriptsTableWidget.cpp b/interface/src/ui/ScriptsTableWidget.cpp index af67b939eb..ac4dc88fee 100644 --- a/interface/src/ui/ScriptsTableWidget.cpp +++ b/interface/src/ui/ScriptsTableWidget.cpp @@ -19,18 +19,20 @@ ScriptsTableWidget::ScriptsTableWidget(QWidget *parent) : setShowGrid(false); setSelectionMode(QAbstractItemView::NoSelection); setEditTriggers(QAbstractItemView::NoEditTriggers); - setStyleSheet("background: transparent;"); + setStyleSheet("QTableWidget { background: transparent; color: #333333; } QToolTip { color: #000000; background: #fdeba5; padding: 2px; }"); + setToolTipDuration(200); + setWordWrap(true); setGeometry(0, 0, parent->width(), parent->height()); } void ScriptsTableWidget::paintEvent(QPaintEvent *event) { QPainter painter(viewport()); - painter.setPen(QColor::fromRgb(196, 196, 196)); + painter.setPen(QColor::fromRgb(225, 225, 225)); int y = 0; for (int i = 0; i < rowCount(); ++i) { - painter.drawLine(0, rowHeight(i) + y, width(), rowHeight(i) + y); + painter.drawLine(6, rowHeight(i) + y, width(), rowHeight(i) + y); y += rowHeight(i); } painter.end(); diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index 7353c19508..f81f30537b 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -14,15 +14,19 @@ Form - background: #f7f7f7; -font-family: Helvetica, Arial, "DejaVu Sans"; + * { + font-family: Helvetica, Arial, sans-serif; +} +QWidget { + background: #f7f7f7; +} 20 10 - 221 + 251 31 @@ -33,6 +37,12 @@ font-size: 20pt; <html><head/><body><p><span style=" font-size:18pt;">Running Scripts</span></p></body></html> + + 0 + + + -1 + @@ -45,7 +55,7 @@ font-size: 20pt; color: #0e7077; -font-size: 14pt; +font: bold 14pt; <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> @@ -70,7 +80,7 @@ font-size: 14pt; background: #0e7077; color: #fff; border-radius: 4px; -font: 14pt 75pt; +font: bold 14pt; Reload all @@ -96,7 +106,7 @@ font: 14pt 75pt; background: #0e7077; color: #fff; border-radius: 4px; -font: 14pt 75pt; +font: bold 14pt; Stop all @@ -117,7 +127,7 @@ font: 14pt 75pt; color: #0e7077; -font-size: 14pt; +font: bold 14pt; <html><head/><body><p><span style=" font-weight:600;">Recently loaded</span></p></body></html> @@ -204,7 +214,6 @@ font-size: 14pt; background: transparent; font-size: 14pt; - reloadAllButton From eae95a57b7b6206be327ee9e0c4403ceff744b25 Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Fri, 4 Apr 2014 23:12:56 +0530 Subject: [PATCH 08/37] UI alignment changes --- interface/interface_en.ts | 30 +++++----- interface/src/Application.cpp | 2 +- interface/src/ui/RunningScriptsWidget.cpp | 27 +++++++-- interface/src/ui/ScriptsTableWidget.cpp | 4 +- interface/ui/runningScriptsWidget.ui | 72 +++++++++++++---------- 5 files changed, 81 insertions(+), 54 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index 5256944949..a497ed6ca7 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -162,51 +162,51 @@ RunningScriptsWidget - + Form - - + + <html><head/><body><p><span style=" font-size:18pt;">Running Scripts</span></p></body></html> - - + + <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> - - + + Reload all Reload All - - + + Stop all Stop All - - + + <html><head/><body><p><span style=" font-weight:600;">Recently loaded</span></p></body></html> - - + + (click a script or use the 1-9 keys to load and run it) - - + + There are no scripts currently running. diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 01cccbde47..b806563c9c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3635,7 +3635,7 @@ void Application::toggleRunningScriptsWidget() if (!_runningScriptsWidget->toggleViewAction()->isChecked()) { _runningScriptsWidget->setGeometry(_window->geometry().topLeft().x(), _window->geometry().topLeft().y(), - 310, _window->height()); + _runningScriptsWidget->width(), _window->height()); _runningScriptsWidget->toggleViewAction()->trigger(); _runningScriptsWidget->grabKeyboard(); _runningScriptsWidget->show(); diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index f27ea9a831..b3b42bfa6b 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -27,7 +27,7 @@ RunningScriptsWidget::RunningScriptsWidget(QDockWidget *parent) : _runningScriptsTable = new ScriptsTableWidget(ui->runningScriptsTableWidget); _runningScriptsTable->setColumnCount(2); - _runningScriptsTable->setColumnWidth(0, 252); + _runningScriptsTable->setColumnWidth(0, 245); _runningScriptsTable->setColumnWidth(1, 22); connect(_runningScriptsTable, &QTableWidget::cellClicked, this, &RunningScriptsWidget::stopScript); @@ -73,6 +73,21 @@ void RunningScriptsWidget::setRunningScripts(const QStringList& list) _runningScriptsTable->setItem(i, 1, closeIcon); } + int y = ui->runningScriptsTableWidget->y() + 12; + for (int i = 0; i < _runningScriptsTable->rowCount(); ++i) { + y += _runningScriptsTable->rowHeight(i); + } + + ui->runningScriptsTableWidget->resize(ui->runningScriptsTableWidget->width(), y - 12); + _runningScriptsTable->resize(_runningScriptsTable->width(), y - 12); + ui->reloadAllButton->move(ui->reloadAllButton->x(), y); + ui->stopAllButton->move(ui->stopAllButton->x(), y); + ui->recentlyLoadedLabel->move(ui->recentlyLoadedLabel->x(), + ui->stopAllButton->y() + ui->stopAllButton->height() + 61); + ui->recentlyLoadedScriptsTableWidget->move(ui->recentlyLoadedScriptsTableWidget->x(), + ui->recentlyLoadedLabel->y() + 19); + + createRecentlyLoadedScriptsTable(); } @@ -143,18 +158,18 @@ void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) void RunningScriptsWidget::paintEvent(QPaintEvent *) { QPainter painter(this); - painter.setPen(QColor::fromRgb(225, 225, 225)); + painter.setPen(QColor::fromRgb(225, 225, 225)); // #e1e1e1 if (ui->currentlyRunningLabel->isVisible()) { // line below the 'Currently Running' label - painter.drawLine(21, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height(), - width() - 22, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height()); + painter.drawLine(36, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height(), + 300, ui->currentlyRunningLabel->y() + ui->currentlyRunningLabel->height()); } if (ui->recentlyLoadedLabel->isVisible()) { // line below the 'Recently loaded' label - painter.drawLine(21, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height(), - width() - 22, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height()); + painter.drawLine(36, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height(), + 300, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height()); } painter.end(); diff --git a/interface/src/ui/ScriptsTableWidget.cpp b/interface/src/ui/ScriptsTableWidget.cpp index ac4dc88fee..6800b56db2 100644 --- a/interface/src/ui/ScriptsTableWidget.cpp +++ b/interface/src/ui/ScriptsTableWidget.cpp @@ -28,11 +28,11 @@ ScriptsTableWidget::ScriptsTableWidget(QWidget *parent) : void ScriptsTableWidget::paintEvent(QPaintEvent *event) { QPainter painter(viewport()); - painter.setPen(QColor::fromRgb(225, 225, 225)); + painter.setPen(QColor::fromRgb(225, 225, 225)); // #e1e1e1 int y = 0; for (int i = 0; i < rowCount(); ++i) { - painter.drawLine(6, rowHeight(i) + y, width(), rowHeight(i) + y); + painter.drawLine(5, rowHeight(i) + y, width(), rowHeight(i) + y); y += rowHeight(i); } painter.end(); diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index f81f30537b..78b16cacff 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -6,7 +6,7 @@ 0 0 - 310 + 323 651 @@ -24,15 +24,16 @@ QWidget { - 20 - 10 + 37 + 29 251 - 31 + 20 color: #0e7077; -font-size: 20pt; +font-size: 20pt; +background: transparent; <html><head/><body><p><span style=" font-size:18pt;">Running Scripts</span></p></body></html> @@ -47,15 +48,16 @@ font-size: 20pt; - 20 - 40 + 36 + 70 270 20 color: #0e7077; -font: bold 14pt; +font: bold 14pt; +background: transparent; <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> @@ -64,7 +66,7 @@ font: bold 14pt; - 20 + 36 230 111 35 @@ -93,9 +95,9 @@ font: bold 14pt; - 144 + 160 230 - 101 + 93 35 @@ -119,9 +121,9 @@ font: bold 14pt; - 20 + 36 280 - 301 + 265 20 @@ -136,10 +138,10 @@ font: bold 14pt; - 20 + 36 590 - 271 - 41 + 203 + 31 @@ -156,10 +158,10 @@ font-size: 14pt; - 270 - 10 - 31 - 31 + 285 + 29 + 16 + 16 @@ -174,8 +176,8 @@ font-size: 14pt; - 20 - 20 + 16 + 16 @@ -185,8 +187,8 @@ font-size: 14pt; - 20 - 60 + 36 + 70 271 51 @@ -198,15 +200,15 @@ font-size: 14pt; There are no scripts currently running. - Qt::AlignCenter + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - 14 + 30 300 - 276 + 272 280 @@ -218,9 +220,9 @@ font-size: 14pt; - 14 - 60 - 276 + 30 + 88 + 272 161 @@ -229,6 +231,16 @@ font-size: 14pt; font-size: 14pt; + widgetTitle + currentlyRunningLabel + recentlyLoadedLabel + recentlyLoadedInstruction + hideWidgetButton + recentlyLoadedScriptsTableWidget + runningScriptsTableWidget + noRunningScriptsLabel + reloadAllButton + stopAllButton From 7b5c733d9ed73a08fb8a6fb3044fb85739022791 Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Sat, 5 Apr 2014 01:10:02 +0530 Subject: [PATCH 09/37] Fixed spacing of number and script name in recently loaded list. --- interface/src/ui/RunningScriptsWidget.cpp | 17 +++++++---------- interface/ui/runningScriptsWidget.ui | 4 ++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index b3b42bfa6b..938cecf31f 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -32,9 +32,8 @@ RunningScriptsWidget::RunningScriptsWidget(QDockWidget *parent) : connect(_runningScriptsTable, &QTableWidget::cellClicked, this, &RunningScriptsWidget::stopScript); _recentlyLoadedScriptsTable = new ScriptsTableWidget(ui->recentlyLoadedScriptsTableWidget); - _recentlyLoadedScriptsTable->setColumnCount(2); - _recentlyLoadedScriptsTable->setColumnWidth(0, 25); - _recentlyLoadedScriptsTable->setColumnWidth(1, 242); + _recentlyLoadedScriptsTable->setColumnCount(1); + _recentlyLoadedScriptsTable->setColumnWidth(0, 265); connect(_recentlyLoadedScriptsTable, &QTableWidget::cellClicked, this, &RunningScriptsWidget::loadScript); @@ -219,15 +218,11 @@ void RunningScriptsWidget::createRecentlyLoadedScriptsTable() _recentlyLoadedScriptsTable->setRowCount(limit); for (int i = 0; i < limit; ++i) { QTableWidgetItem *scriptName = new QTableWidgetItem; - scriptName->setText(QFileInfo(_recentlyLoadedScripts.at(i)).fileName()); + scriptName->setText(QString::number(i+1) + ". " +QFileInfo(_recentlyLoadedScripts.at(i)).fileName()); scriptName->setToolTip(_recentlyLoadedScripts.at(i)); scriptName->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); - QTableWidgetItem *number = new QTableWidgetItem; - number->setText(QString::number(i+1) + "."); - number->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); - _recentlyLoadedScriptsTable->setItem(i, 0, number); - _recentlyLoadedScriptsTable->setItem(i, 1, scriptName); + _recentlyLoadedScriptsTable->setItem(i, 0, scriptName); } int y = ui->recentlyLoadedScriptsTableWidget->y() + 15; @@ -235,7 +230,9 @@ void RunningScriptsWidget::createRecentlyLoadedScriptsTable() y += _recentlyLoadedScriptsTable->rowHeight(i); } - ui->recentlyLoadedInstruction->setGeometry(20, y, width() - 20, ui->recentlyLoadedInstruction->height()); + ui->recentlyLoadedInstruction->setGeometry(36, y, + ui->recentlyLoadedInstruction->width(), + ui->recentlyLoadedInstruction->height()); repaint(); } diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index 78b16cacff..28ef11e1b5 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -140,8 +140,8 @@ font: bold 14pt; 36 590 - 203 - 31 + 211 + 41 From 136b91feb565263ea554699be61fa2cca9b997f7 Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Sat, 5 Apr 2014 01:32:21 +0530 Subject: [PATCH 10/37] Align the buttons text properly --- interface/ui/runningScriptsWidget.ui | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index 28ef11e1b5..e79496afb8 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -82,7 +82,8 @@ background: transparent; background: #0e7077; color: #fff; border-radius: 4px; -font: bold 14pt; +font: bold 14pt; +padding-top: 3px; Reload all @@ -108,7 +109,8 @@ font: bold 14pt; background: #0e7077; color: #fff; border-radius: 4px; -font: bold 14pt; +font: bold 14pt; +padding-top: 3px; Stop all From ba7c69678686ee08dd23c18defc5f1bada64eca1 Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Tue, 8 Apr 2014 23:38:49 +0530 Subject: [PATCH 11/37] child like behaviour for the widget --- interface/interface_en.ts | 34 ++++++------ interface/src/Application.cpp | 41 ++++++++++----- interface/src/Application.h | 10 ++-- interface/src/GLCanvas.cpp | 10 ++-- interface/src/GLCanvas.h | 16 +++--- interface/src/MainWindow.cpp | 64 +++++++++++++++++++++++ interface/src/MainWindow.h | 31 +++++++++++ interface/src/ui/RunningScriptsWidget.cpp | 42 +++++++++++++-- interface/src/ui/RunningScriptsWidget.h | 9 ++++ interface/src/ui/ScriptsTableWidget.cpp | 2 +- 10 files changed, 210 insertions(+), 49 deletions(-) create mode 100644 interface/src/MainWindow.cpp create mode 100644 interface/src/MainWindow.h diff --git a/interface/interface_en.ts b/interface/interface_en.ts index a497ed6ca7..543a032a4f 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) @@ -162,51 +162,51 @@ RunningScriptsWidget - + Form - + <html><head/><body><p><span style=" font-size:18pt;">Running Scripts</span></p></body></html> - + <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> - - + + Reload all Reload All - - + + Stop all Stop All - - + + <html><head/><body><p><span style=" font-weight:600;">Recently loaded</span></p></body></html> - - + + (click a script or use the 1-9 keys to load and run it) - - + + There are no scripts currently running. diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b806563c9c..752dff28a6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -135,7 +134,7 @@ QString& Application::resourcesPath() { Application::Application(int& argc, char** argv, timeval &startup_time) : QApplication(argc, argv), - _window(new QMainWindow(desktop())), + _window(new MainWindow(desktop())), _glWidget(new GLCanvas()), _statsExpanded(false), _nodeThread(new QThread(this)), @@ -172,7 +171,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _resetRecentMaxPacketsSoon(true), _previousScriptLocation(), _logger(new FileLogger(this)), - _runningScriptsWidget(new RunningScriptsWidget) + _runningScriptsWidget(new RunningScriptsWidget), + _runningScriptsWidgetWasVisible(false) { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -335,7 +335,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : LocalVoxelsList::getInstance()->addPersistantTree(CLIPBOARD_TREE_NAME, &_clipboard); _window->addDockWidget(Qt::NoDockWidgetArea, _runningScriptsWidget); - _runningScriptsWidget->hide(); _runningScriptsWidget->setRunningScripts(getRunningScripts()); connect(_runningScriptsWidget, &RunningScriptsWidget::stopScriptName, this, &Application::stopScript); @@ -352,6 +351,10 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : // do this as late as possible so that all required subsystems are inialized loadScripts(); } + + connect(_window, &MainWindow::windowGeometryChanged, + _runningScriptsWidget, &RunningScriptsWidget::setBoundary); + connect(_window, &MainWindow::windowShown, this, &Application::manageRunningScriptsWidgetVisibility); } Application::~Application() { @@ -622,7 +625,7 @@ void Application::resizeGL(int width, int height) { updateProjectionMatrix(); glLoadIdentity(); - if (_runningScriptsWidget->isVisible()) { + if (_runningScriptsWidget->toggleViewAction()->isChecked()) { _runningScriptsWidget->setGeometry(_window->geometry().topLeft().x(), _window->geometry().topLeft().y(), _runningScriptsWidget->width(), _window->height()); @@ -3630,19 +3633,33 @@ void Application::reloadAllScripts() { } } +void Application::manageRunningScriptsWidgetVisibility(bool shown) +{ + if (_runningScriptsWidgetWasVisible && shown) { + _runningScriptsWidget->setWindowFlags(Qt::SubWindow | Qt::FramelessWindowHint | + Qt::WindowStaysOnTopHint); + _runningScriptsWidget->show(); + } else { + _runningScriptsWidget->setWindowFlags(Qt::SubWindow | Qt::FramelessWindowHint); + _runningScriptsWidget->hide(); + } +} + void Application::toggleRunningScriptsWidget() { - if (!_runningScriptsWidget->toggleViewAction()->isChecked()) { + if (_runningScriptsWidget->toggleViewAction()->isChecked()) { + _runningScriptsWidget->toggleViewAction()->setChecked(false); + _runningScriptsWidget->hide(); + _runningScriptsWidgetWasVisible = false; + } else { + _runningScriptsWidget->setBoundary(QRect(_window->geometry().topLeft(), + _window->size())); _runningScriptsWidget->setGeometry(_window->geometry().topLeft().x(), _window->geometry().topLeft().y(), _runningScriptsWidget->width(), _window->height()); - _runningScriptsWidget->toggleViewAction()->trigger(); - _runningScriptsWidget->grabKeyboard(); + _runningScriptsWidget->toggleViewAction()->setChecked(true); _runningScriptsWidget->show(); - } else { - _runningScriptsWidget->toggleViewAction()->trigger(); - _runningScriptsWidget->releaseKeyboard(); - _runningScriptsWidget->hide(); + _runningScriptsWidgetWasVisible = true; } } diff --git a/interface/src/Application.h b/interface/src/Application.h index 221a81478e..4196ed7ca8 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -33,6 +33,7 @@ #include #include +#include "MainWindow.h" #include "Audio.h" #include "BuckyBalls.h" #include "Camera.h" @@ -78,7 +79,6 @@ class QAction; class QActionGroup; class QGLWidget; class QKeyEvent; -class QMainWindow; class QMouseEvent; class QNetworkAccessManager; class QSettings; @@ -127,6 +127,7 @@ public: void keyReleaseEvent(QKeyEvent* event); void focusOutEvent(QFocusEvent* event); + void focusInEvent(QFocusEvent* event); void mouseMoveEvent(QMouseEvent* event); void mousePressEvent(QMouseEvent* event); @@ -180,7 +181,7 @@ public: QSettings* lockSettings() { _settingsMutex.lock(); return _settings; } void unlockSettings() { _settingsMutex.unlock(); } - QMainWindow* getWindow() { return _window; } + MainWindow* getWindow() { return _window; } NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; } void lockOctreeSceneStats() { _octreeSceneStatsLock.lockForRead(); } void unlockOctreeSceneStats() { _octreeSceneStatsLock.unlock(); } @@ -290,6 +291,8 @@ private slots: void parseVersionXml(); + void manageRunningScriptsWidgetVisibility(bool shown); + private: void resetCamerasOnResizeGL(Camera& camera, int width, int height); void updateProjectionMatrix(); @@ -353,7 +356,7 @@ private: void displayRearMirrorTools(); - QMainWindow* _window; + MainWindow* _window; GLCanvas* _glWidget; // our GLCanvas has a couple extra features bool _statsExpanded; @@ -502,6 +505,7 @@ private: RunningScriptsWidget* _runningScriptsWidget; QHash _scriptEnginesHash; + bool _runningScriptsWidgetWasVisible; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index 513dcfe40c..73feb31042 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -21,8 +21,8 @@ GLCanvas::GLCanvas() : QGLWidget(QGLFormat(QGL::NoDepthBuffer)), { } -bool GLCanvas::isThrottleRendering() const { - return _throttleRendering || Application::getInstance()->getWindow()->isMinimized(); +bool GLCanvas::isThrottleRendering() const { + return _throttleRendering || Application::getInstance()->getWindow()->isMinimized(); } void GLCanvas::initializeGL() { @@ -31,7 +31,7 @@ void GLCanvas::initializeGL() { setAcceptDrops(true); connect(Application::getInstance(), SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(activeChanged(Qt::ApplicationState))); connect(&_frameTimer, SIGNAL(timeout()), this, SLOT(throttleRender())); - + // Note, we *DO NOT* want Qt to automatically swap buffers for us. This results in the "ringing" bug mentioned in WL#19514 when we're throttling the framerate. setAutoBufferSwap(false); } @@ -78,14 +78,14 @@ void GLCanvas::activeChanged(Qt::ApplicationState state) { _frameTimer.stop(); _throttleRendering = false; break; - + case Qt::ApplicationSuspended: case Qt::ApplicationHidden: // If we're hidden or are about to suspend, don't render anything. _throttleRendering = false; _frameTimer.stop(); break; - + default: // Otherwise, throttle. if (!_throttleRendering) { diff --git a/interface/src/GLCanvas.h b/interface/src/GLCanvas.h index f7f7fb7c20..5e31a1422e 100644 --- a/interface/src/GLCanvas.h +++ b/interface/src/GLCanvas.h @@ -19,31 +19,31 @@ public: GLCanvas(); bool isThrottleRendering() const; protected: - + QTimer _frameTimer; bool _throttleRendering; int _idleRenderInterval; - + virtual void initializeGL(); virtual void paintGL(); virtual void resizeGL(int width, int height); - + virtual void keyPressEvent(QKeyEvent* event); virtual void keyReleaseEvent(QKeyEvent* event); - + virtual void focusOutEvent(QFocusEvent* event); - + virtual void mouseMoveEvent(QMouseEvent* event); virtual void mousePressEvent(QMouseEvent* event); virtual void mouseReleaseEvent(QMouseEvent* event); - + virtual bool event(QEvent* event); - + virtual void wheelEvent(QWheelEvent* event); virtual void dragEnterEvent(QDragEnterEvent *event); virtual void dropEvent(QDropEvent* event); - + private slots: void activeChanged(Qt::ApplicationState state); void throttleRender(); diff --git a/interface/src/MainWindow.cpp b/interface/src/MainWindow.cpp new file mode 100644 index 0000000000..86d24e1148 --- /dev/null +++ b/interface/src/MainWindow.cpp @@ -0,0 +1,64 @@ +// +// MainWindow.cpp +// interface +// +// Created by Mohammed Nafees on 04/06/2014. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. + +#include "MainWindow.h" + +#include +#include +#include +#include +#include +#include + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent) +{ +} + +void MainWindow::moveEvent(QMoveEvent *e) +{ + emit windowGeometryChanged(QRect(e->pos(), size())); +} + +void MainWindow::resizeEvent(QResizeEvent *e) +{ + emit windowGeometryChanged(QRect(QPoint(x(), y()), e->size())); +} + +void MainWindow::showEvent(QShowEvent *e) +{ + if (e->spontaneous()) { + emit windowShown(true); + } +} + +void MainWindow::hideEvent(QHideEvent *e) +{ + if (e->spontaneous()) { + emit windowShown(false); + } +} + +void MainWindow::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::WindowStateChange) { + QWindowStateChangeEvent *event = static_cast(e); + if ((event->oldState() == Qt::WindowNoState || + event->oldState() == Qt::WindowMaximized) && + windowState() == Qt::WindowMinimized) { + emit windowShown(false); + } else { + emit windowShown(true); + } + } else if (e->type() == QEvent::ActivationChange) { + if (isActiveWindow()) { + emit windowShown(true); + } else { + emit windowShown(false); + } + } +} diff --git a/interface/src/MainWindow.h b/interface/src/MainWindow.h new file mode 100644 index 0000000000..5c4168923b --- /dev/null +++ b/interface/src/MainWindow.h @@ -0,0 +1,31 @@ +// +// MainWindow.h +// interface +// +// Created by Mohammed Nafees on 04/06/2014. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. + +#ifndef __hifi__MainWindow__ +#define __hifi__MainWindow__ + +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + explicit MainWindow(QWidget *parent = 0); + +signals: + void windowGeometryChanged(QRect geometry); + void windowShown(bool shown); + +protected: + virtual void moveEvent(QMoveEvent *e); + virtual void resizeEvent(QResizeEvent *e); + virtual void showEvent(QShowEvent *e); + virtual void hideEvent(QHideEvent *e); + virtual void changeEvent(QEvent *e); +}; + +#endif /* defined(__hifi__MainWindow__) */ diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 938cecf31f..adb4669a31 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -18,12 +18,13 @@ RunningScriptsWidget::RunningScriptsWidget(QDockWidget *parent) : QDockWidget(parent), - ui(new Ui::RunningScriptsWidget) + ui(new Ui::RunningScriptsWidget), + _mousePressed(false), + _mousePosition(QPoint()) { ui->setupUi(this); - // remove the title bar (see the Qt docs on setTitleBarWidget) - setTitleBarWidget(new QWidget()); + setWindowFlags(Qt::SubWindow | Qt::FramelessWindowHint); _runningScriptsTable = new ScriptsTableWidget(ui->runningScriptsTableWidget); _runningScriptsTable->setColumnCount(2); @@ -50,6 +51,11 @@ RunningScriptsWidget::~RunningScriptsWidget() delete ui; } +void RunningScriptsWidget::setBoundary(const QRect &rect) +{ + _boundary = rect; +} + void RunningScriptsWidget::setRunningScripts(const QStringList& list) { _runningScriptsTable->setRowCount(list.size()); @@ -90,6 +96,36 @@ void RunningScriptsWidget::setRunningScripts(const QStringList& list) createRecentlyLoadedScriptsTable(); } +void RunningScriptsWidget::mousePressEvent(QMouseEvent *e) +{ + if (e->button() == Qt::LeftButton) { + _mousePressed = true; + _mousePosition = e->pos(); + } else { + _mousePressed = false; + _mousePosition = QPoint(); + } +} + +void RunningScriptsWidget::mouseMoveEvent(QMouseEvent *e) +{ + if (_mousePressed) { + QPoint newPosition = mapToParent(e->pos() - _mousePosition); + if (newPosition.x() >= _boundary.x() && + newPosition.x() <= (_boundary.width() - width())) { + move(newPosition.x(), _boundary.y()); + } + } +} + +void RunningScriptsWidget::mouseReleaseEvent(QMouseEvent *e) +{ + if (e->button() == Qt::LeftButton) { + _mousePressed = false; + _mousePosition = QPoint(); + } +} + void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) { switch(e->key()) { diff --git a/interface/src/ui/RunningScriptsWidget.h b/interface/src/ui/RunningScriptsWidget.h index 51c19028cd..d34b15d0eb 100644 --- a/interface/src/ui/RunningScriptsWidget.h +++ b/interface/src/ui/RunningScriptsWidget.h @@ -29,9 +29,15 @@ signals: void stopScriptName(const QString& name); protected: + virtual void mousePressEvent(QMouseEvent *e); + virtual void mouseMoveEvent(QMouseEvent *e); + virtual void mouseReleaseEvent(QMouseEvent *e); virtual void keyPressEvent(QKeyEvent *e); virtual void paintEvent(QPaintEvent *); +public slots: + void setBoundary(const QRect& rect); + private slots: void stopScript(int row, int column); void loadScript(int row, int column); @@ -43,6 +49,9 @@ private: ScriptsTableWidget *_recentlyLoadedScriptsTable; QStringList _recentlyLoadedScripts; QString _lastStoppedScript; + QRect _boundary; + bool _mousePressed; + QPoint _mousePosition; void createRecentlyLoadedScriptsTable(); }; diff --git a/interface/src/ui/ScriptsTableWidget.cpp b/interface/src/ui/ScriptsTableWidget.cpp index 6800b56db2..b483664c29 100644 --- a/interface/src/ui/ScriptsTableWidget.cpp +++ b/interface/src/ui/ScriptsTableWidget.cpp @@ -19,7 +19,7 @@ ScriptsTableWidget::ScriptsTableWidget(QWidget *parent) : setShowGrid(false); setSelectionMode(QAbstractItemView::NoSelection); setEditTriggers(QAbstractItemView::NoEditTriggers); - setStyleSheet("QTableWidget { background: transparent; color: #333333; } QToolTip { color: #000000; background: #fdeba5; padding: 2px; }"); + setStyleSheet("QTableWidget { background: transparent; color: #333333; } QToolTip { color: #000000; background: #f9f6e4; padding: 2px; }"); setToolTipDuration(200); setWordWrap(true); setGeometry(0, 0, parent->width(), parent->height()); From dd74ea64e7161827c021147f9082ff729f2c9814 Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Thu, 24 Apr 2014 17:18:24 +0530 Subject: [PATCH 12/37] Further changes for child like behaviour --- interface/interface_en.ts | 4 ++-- interface/src/Application.cpp | 11 +++-------- interface/src/MainWindow.cpp | 5 +++++ interface/src/ui/RunningScriptsWidget.cpp | 6 +++++- interface/src/ui/RunningScriptsWidget.h | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index 543a032a4f..aa979781de 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -14,12 +14,12 @@ - + Open Script - + JavaScript Files (*.js) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 752dff28a6..df59b6574f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -625,7 +625,7 @@ void Application::resizeGL(int width, int height) { updateProjectionMatrix(); glLoadIdentity(); - if (_runningScriptsWidget->toggleViewAction()->isChecked()) { + if (_runningScriptsWidgetWasVisible) { _runningScriptsWidget->setGeometry(_window->geometry().topLeft().x(), _window->geometry().topLeft().y(), _runningScriptsWidget->width(), _window->height()); @@ -3636,19 +3636,15 @@ void Application::reloadAllScripts() { void Application::manageRunningScriptsWidgetVisibility(bool shown) { if (_runningScriptsWidgetWasVisible && shown) { - _runningScriptsWidget->setWindowFlags(Qt::SubWindow | Qt::FramelessWindowHint | - Qt::WindowStaysOnTopHint); _runningScriptsWidget->show(); - } else { - _runningScriptsWidget->setWindowFlags(Qt::SubWindow | Qt::FramelessWindowHint); + } else if (_runningScriptsWidgetWasVisible && !shown) { _runningScriptsWidget->hide(); } } void Application::toggleRunningScriptsWidget() { - if (_runningScriptsWidget->toggleViewAction()->isChecked()) { - _runningScriptsWidget->toggleViewAction()->setChecked(false); + if (_runningScriptsWidgetWasVisible) { _runningScriptsWidget->hide(); _runningScriptsWidgetWasVisible = false; } else { @@ -3657,7 +3653,6 @@ void Application::toggleRunningScriptsWidget() _runningScriptsWidget->setGeometry(_window->geometry().topLeft().x(), _window->geometry().topLeft().y(), _runningScriptsWidget->width(), _window->height()); - _runningScriptsWidget->toggleViewAction()->setChecked(true); _runningScriptsWidget->show(); _runningScriptsWidgetWasVisible = true; } diff --git a/interface/src/MainWindow.cpp b/interface/src/MainWindow.cpp index 86d24e1148..4711d97232 100644 --- a/interface/src/MainWindow.cpp +++ b/interface/src/MainWindow.cpp @@ -22,11 +22,13 @@ MainWindow::MainWindow(QWidget *parent) : void MainWindow::moveEvent(QMoveEvent *e) { emit windowGeometryChanged(QRect(e->pos(), size())); + QMainWindow::moveEvent(e); } void MainWindow::resizeEvent(QResizeEvent *e) { emit windowGeometryChanged(QRect(QPoint(x(), y()), e->size())); + QMainWindow::resizeEvent(e); } void MainWindow::showEvent(QShowEvent *e) @@ -34,6 +36,7 @@ void MainWindow::showEvent(QShowEvent *e) if (e->spontaneous()) { emit windowShown(true); } + QMainWindow::showEvent(e); } void MainWindow::hideEvent(QHideEvent *e) @@ -41,6 +44,7 @@ void MainWindow::hideEvent(QHideEvent *e) if (e->spontaneous()) { emit windowShown(false); } + QMainWindow::hideEvent(e); } void MainWindow::changeEvent(QEvent *e) @@ -61,4 +65,5 @@ void MainWindow::changeEvent(QEvent *e) emit windowShown(false); } } + QMainWindow::changeEvent(e); } diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index adb4669a31..826aaf7a6a 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -16,7 +16,7 @@ #include "Application.h" -RunningScriptsWidget::RunningScriptsWidget(QDockWidget *parent) : +RunningScriptsWidget::RunningScriptsWidget(QWidget *parent) : QDockWidget(parent), ui(new Ui::RunningScriptsWidget), _mousePressed(false), @@ -105,6 +105,7 @@ void RunningScriptsWidget::mousePressEvent(QMouseEvent *e) _mousePressed = false; _mousePosition = QPoint(); } + QWidget::mousePressEvent(e); } void RunningScriptsWidget::mouseMoveEvent(QMouseEvent *e) @@ -116,6 +117,7 @@ void RunningScriptsWidget::mouseMoveEvent(QMouseEvent *e) move(newPosition.x(), _boundary.y()); } } + QWidget::mouseMoveEvent(e); } void RunningScriptsWidget::mouseReleaseEvent(QMouseEvent *e) @@ -124,6 +126,7 @@ void RunningScriptsWidget::mouseReleaseEvent(QMouseEvent *e) _mousePressed = false; _mousePosition = QPoint(); } + QWidget::mouseReleaseEvent(e); } void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) @@ -188,6 +191,7 @@ void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) default: break; } + QWidget::keyPressEvent(e); } void RunningScriptsWidget::paintEvent(QPaintEvent *) diff --git a/interface/src/ui/RunningScriptsWidget.h b/interface/src/ui/RunningScriptsWidget.h index d34b15d0eb..73dc8e3887 100644 --- a/interface/src/ui/RunningScriptsWidget.h +++ b/interface/src/ui/RunningScriptsWidget.h @@ -20,7 +20,7 @@ class RunningScriptsWidget : public QDockWidget { Q_OBJECT public: - explicit RunningScriptsWidget(QDockWidget *parent = 0); + explicit RunningScriptsWidget(QWidget *parent = 0); ~RunningScriptsWidget(); void setRunningScripts(const QStringList& list); From a86af6b07f83cffa314a8d54067c5ab3e0589935 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 24 Apr 2014 14:05:09 -0700 Subject: [PATCH 13/37] Add Load Script button to RunningScripts Dialog --- interface/src/ui/RunningScriptsWidget.cpp | 2 + interface/ui/runningScriptsWidget.ui | 54 +++++++++++++++++++---- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 94a53c4aa5..602721227d 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -51,6 +51,8 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget *parent) : Application::getInstance(), &Application::reloadAllScripts); connect(ui->stopAllButton, &QPushButton::clicked, this, &RunningScriptsWidget::allScriptsStopped); + connect(ui->loadScriptButton, &QPushButton::clicked, + Application::getInstance(), &Application::loadDialog); } RunningScriptsWidget::~RunningScriptsWidget() diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index b8c690f16e..b58de97179 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -7,7 +7,7 @@ 0 0 323 - 651 + 894 @@ -49,7 +49,7 @@ background: transparent; 36 - 70 + 110 270 20 @@ -67,7 +67,7 @@ background: transparent; 36 - 230 + 270 111 35 @@ -88,12 +88,16 @@ padding-top: 3px; Reload all + + + ../resources/images/reload.svg../resources/images/reload.svg + 160 - 230 + 270 93 35 @@ -111,12 +115,16 @@ padding-top: 3px; Stop all + + + ../resources/images/stop.svg../resources/images/stop.svg + 36 - 280 + 320 265 20 @@ -133,7 +141,7 @@ font: bold 14pt; 36 - 590 + 630 211 41 @@ -178,7 +186,7 @@ font-size: 14pt; 36 - 70 + 110 271 51 @@ -197,7 +205,7 @@ font-size: 14pt; 30 - 300 + 340 272 280 @@ -211,7 +219,7 @@ font-size: 14pt; 30 - 88 + 128 272 161 @@ -221,6 +229,33 @@ font-size: 14pt; font-size: 14pt; + + + + 30 + 70 + 111 + 35 + + + + PointingHandCursor + + + background: #0e7077; +color: #fff; +border-radius: 4px; +font: bold 14pt; +padding-top: 3px; + + + Load script + + + + ../resources/images/plus.svg../resources/images/plus.svg + + widgetTitle currentlyRunningLabel recentlyLoadedLabel @@ -231,6 +266,7 @@ font-size: 14pt; noRunningScriptsLabel reloadAllButton stopAllButton + loadScriptButton From 225c02251156dead14e596f5d36dfed9c422f5d8 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 25 Apr 2014 10:10:50 -0700 Subject: [PATCH 14/37] Update RunningScriptsWidget to use FramelessDialog --- interface/src/Application.cpp | 13 ++----------- interface/src/ui/RunningScriptsWidget.cpp | 9 ++++----- interface/src/ui/RunningScriptsWidget.h | 6 ++---- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 30791a29b4..e812116487 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -164,7 +164,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _bytesPerSecond(0), _previousScriptLocation(), _logger(new FileLogger(this)), - _runningScriptsWidget(new RunningScriptsWidget), + _runningScriptsWidget(new RunningScriptsWidget(_window)), _runningScriptsWidgetWasVisible(false) { // init GnuTLS for DTLS with domain-servers @@ -332,7 +332,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : LocalVoxelsList::getInstance()->addPersistantTree(DOMAIN_TREE_NAME, _voxels.getTree()); LocalVoxelsList::getInstance()->addPersistantTree(CLIPBOARD_TREE_NAME, &_clipboard); - _window->addDockWidget(Qt::NoDockWidgetArea, _runningScriptsWidget); _runningScriptsWidget->setRunningScripts(getRunningScripts()); connect(_runningScriptsWidget, &RunningScriptsWidget::stopScriptName, this, &Application::stopScript); @@ -356,7 +355,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(_window, &MainWindow::windowGeometryChanged, _runningScriptsWidget, &RunningScriptsWidget::setBoundary); - connect(_window, &MainWindow::windowShown, this, &Application::manageRunningScriptsWidgetVisibility); //When -url in command line, teleport to location urlGoTo(argc, constArgv); @@ -705,11 +703,6 @@ void Application::resizeGL(int width, int height) { updateProjectionMatrix(); glLoadIdentity(); - if (_runningScriptsWidgetWasVisible) { - _runningScriptsWidget->setGeometry(_window->geometry().topLeft().x(), - _window->geometry().topLeft().y(), - _runningScriptsWidget->width(), _window->height()); - } // update Stats width int horizontalOffset = 0; if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { @@ -3350,15 +3343,13 @@ void Application::manageRunningScriptsWidgetVisibility(bool shown) void Application::toggleRunningScriptsWidget() { + qDebug() << "RS"; if (_runningScriptsWidgetWasVisible) { _runningScriptsWidget->hide(); _runningScriptsWidgetWasVisible = false; } else { _runningScriptsWidget->setBoundary(QRect(_window->geometry().topLeft(), _window->size())); - _runningScriptsWidget->setGeometry(_window->geometry().topLeft().x(), - _window->geometry().topLeft().y(), - _runningScriptsWidget->width(), _window->height()); _runningScriptsWidget->show(); _runningScriptsWidgetWasVisible = true; } diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 602721227d..bc2a27afaf 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -20,14 +20,13 @@ #include "Application.h" RunningScriptsWidget::RunningScriptsWidget(QWidget *parent) : - QDockWidget(parent), + FramelessDialog(parent, 0, POSITION_LEFT), ui(new Ui::RunningScriptsWidget), _mousePressed(false), _mousePosition(QPoint()) { ui->setupUi(this); - setWindowFlags(Qt::SubWindow | Qt::FramelessWindowHint); ui->hideWidgetButton->setIcon(QIcon(Application::resourcesPath() + "images/close.svg")); ui->reloadAllButton->setIcon(QIcon(Application::resourcesPath() + "images/reload.svg")); @@ -114,7 +113,7 @@ void RunningScriptsWidget::mousePressEvent(QMouseEvent *e) _mousePressed = false; _mousePosition = QPoint(); } - QWidget::mousePressEvent(e); + FramelessDialog::mousePressEvent(e); } void RunningScriptsWidget::mouseMoveEvent(QMouseEvent *e) @@ -126,7 +125,7 @@ void RunningScriptsWidget::mouseMoveEvent(QMouseEvent *e) move(newPosition.x(), _boundary.y()); } } - QWidget::mouseMoveEvent(e); + FramelessDialog::mouseMoveEvent(e); } void RunningScriptsWidget::mouseReleaseEvent(QMouseEvent *e) @@ -201,7 +200,7 @@ void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) break; } - QWidget::keyPressEvent(e); + FramelessDialog::keyPressEvent(e); } void RunningScriptsWidget::paintEvent(QPaintEvent *) diff --git a/interface/src/ui/RunningScriptsWidget.h b/interface/src/ui/RunningScriptsWidget.h index 72f284fd2d..a4ee2fe57f 100644 --- a/interface/src/ui/RunningScriptsWidget.h +++ b/interface/src/ui/RunningScriptsWidget.h @@ -12,16 +12,14 @@ #ifndef hifi_RunningScriptsWidget_h #define hifi_RunningScriptsWidget_h -// Qt -#include - +#include "FramelessDialog.h" #include "ScriptsTableWidget.h" namespace Ui { class RunningScriptsWidget; } -class RunningScriptsWidget : public QDockWidget +class RunningScriptsWidget : public FramelessDialog { Q_OBJECT public: From dd844437b6acf4f6a1ac8d43177ceee59ce37926 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 25 Apr 2014 10:11:22 -0700 Subject: [PATCH 15/37] Add option to disallow resizing in FramelessDialog --- interface/src/ui/FramelessDialog.cpp | 3 ++- interface/src/ui/FramelessDialog.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/FramelessDialog.cpp b/interface/src/ui/FramelessDialog.cpp index 4919e99db6..ad4b511645 100644 --- a/interface/src/ui/FramelessDialog.cpp +++ b/interface/src/ui/FramelessDialog.cpp @@ -16,6 +16,7 @@ const int RESIZE_HANDLE_WIDTH = 7; FramelessDialog::FramelessDialog(QWidget *parent, Qt::WindowFlags flags, Position position) : QDialog(parent, flags | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint), + _allowResize(true), _isResizing(false), _resizeInitialWidth(0), _selfHidden(false), @@ -107,7 +108,7 @@ void FramelessDialog::resizeAndPosition(bool resizeParent) { } void FramelessDialog::mousePressEvent(QMouseEvent* mouseEvent) { - if (mouseEvent->button() == Qt::LeftButton) { + if (_allowResize && mouseEvent->button() == Qt::LeftButton) { bool hitLeft = _position == POSITION_LEFT && abs(mouseEvent->pos().x() - size().width()) < RESIZE_HANDLE_WIDTH; bool hitRight = _position == POSITION_RIGHT && mouseEvent->pos().x() < RESIZE_HANDLE_WIDTH; if (hitLeft || hitRight) { diff --git a/interface/src/ui/FramelessDialog.h b/interface/src/ui/FramelessDialog.h index 828602a5db..450ae5333f 100644 --- a/interface/src/ui/FramelessDialog.h +++ b/interface/src/ui/FramelessDialog.h @@ -23,6 +23,8 @@ public: FramelessDialog(QWidget* parent = 0, Qt::WindowFlags flags = 0, Position position = POSITION_LEFT); void setStyleSheetFile(const QString& fileName); + void setAllowResize(bool allowResize) { _allowResize = allowResize; }; + bool getAllowResize() { return _allowResize; }; protected: virtual void mouseMoveEvent(QMouseEvent* mouseEvent); @@ -35,6 +37,7 @@ protected: private: void resizeAndPosition(bool resizeParent = true); + bool _allowResize; bool _isResizing; int _resizeInitialWidth; bool _selfHidden; ///< true when the dialog itself because of a window event (deactivation or minimization) From 76d809093818052612bb1eefa3039b3fc7d9df91 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 25 Apr 2014 10:11:34 -0700 Subject: [PATCH 16/37] Disallow resizing of running scripts widget --- interface/src/ui/RunningScriptsWidget.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index bc2a27afaf..e996cb09d9 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -27,6 +27,7 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget *parent) : { ui->setupUi(this); + setAllowResize(false); ui->hideWidgetButton->setIcon(QIcon(Application::resourcesPath() + "images/close.svg")); ui->reloadAllButton->setIcon(QIcon(Application::resourcesPath() + "images/reload.svg")); From 61e8a20550c0d03bd72213547425b96cd90990e3 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 25 Apr 2014 10:11:56 -0700 Subject: [PATCH 17/37] Update running scripts widget to forward mouse release events --- interface/src/ui/RunningScriptsWidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index e996cb09d9..4a26f141cc 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -135,7 +135,7 @@ void RunningScriptsWidget::mouseReleaseEvent(QMouseEvent *e) _mousePressed = false; _mousePosition = QPoint(); } - QWidget::mouseReleaseEvent(e); + FramelessDialog::mouseReleaseEvent(e); } void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) From 5a8a78e7b890ce90193eecca0ef8dcf305b1ffd0 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 25 Apr 2014 10:14:18 -0700 Subject: [PATCH 18/37] Update location of Load Script button --- interface/ui/runningScriptsWidget.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index b58de97179..6abd0f2d5a 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -232,7 +232,7 @@ font-size: 14pt; - 30 + 36 70 111 35 From c3d8cce4a6776158e78aedaf3dacb2a35ac3c13b Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 25 Apr 2014 10:30:56 -0700 Subject: [PATCH 19/37] Add plus icon to LoadScript button --- interface/src/ui/RunningScriptsWidget.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 4a26f141cc..edf33f21d2 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -32,6 +32,7 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget *parent) : ui->hideWidgetButton->setIcon(QIcon(Application::resourcesPath() + "images/close.svg")); ui->reloadAllButton->setIcon(QIcon(Application::resourcesPath() + "images/reload.svg")); ui->stopAllButton->setIcon(QIcon(Application::resourcesPath() + "images/stop.svg")); + ui->loadScriptButton->setIcon(QIcon(Application::resourcesPath() + "images/plus.svg")); _runningScriptsTable = new ScriptsTableWidget(ui->runningScriptsTableWidget); _runningScriptsTable->setColumnCount(2); From 8480d024145a3cf415d40225023ff0657d5cffd4 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 25 Apr 2014 12:44:46 -0700 Subject: [PATCH 20/37] Fix 1-9 keys not working in Running Scripts widget --- interface/src/ui/ScriptsTableWidget.cpp | 6 ++++++ interface/src/ui/ScriptsTableWidget.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/interface/src/ui/ScriptsTableWidget.cpp b/interface/src/ui/ScriptsTableWidget.cpp index b483664c29..12150ae625 100644 --- a/interface/src/ui/ScriptsTableWidget.cpp +++ b/interface/src/ui/ScriptsTableWidget.cpp @@ -10,6 +10,7 @@ #include #include #include +#include ScriptsTableWidget::ScriptsTableWidget(QWidget *parent) : QTableWidget(parent) @@ -39,3 +40,8 @@ void ScriptsTableWidget::paintEvent(QPaintEvent *event) QTableWidget::paintEvent(event); } + +void ScriptsTableWidget::keyPressEvent(QKeyEvent *event) { + // Ignore keys so they will propagate correctly + event->ignore(); +} diff --git a/interface/src/ui/ScriptsTableWidget.h b/interface/src/ui/ScriptsTableWidget.h index f4726ab26d..ee9f87928a 100644 --- a/interface/src/ui/ScriptsTableWidget.h +++ b/interface/src/ui/ScriptsTableWidget.h @@ -8,6 +8,7 @@ #ifndef __hifi__ScriptsTableWidget__ #define __hifi__ScriptsTableWidget__ +#include #include class ScriptsTableWidget : public QTableWidget @@ -18,6 +19,7 @@ public: protected: virtual void paintEvent(QPaintEvent *event); + virtual void keyPressEvent(QKeyEvent *event); }; #endif /* defined(__hifi__ScriptsTableWidget__) */ From 958238efa76b07b408124d9fc78213a890e3ecbc Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 25 Apr 2014 12:45:26 -0700 Subject: [PATCH 21/37] Cleanup implementation of script loading to reduce copy/paste --- interface/src/ui/RunningScriptsWidget.cpp | 43 +++++++++-------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index edf33f21d2..3d3aa66e92 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -141,66 +141,55 @@ void RunningScriptsWidget::mouseReleaseEvent(QMouseEvent *e) void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) { + int loadScriptNumber = -1; switch(e->key()) { case Qt::Key_Escape: Application::getInstance()->toggleRunningScriptsWidget(); break; case Qt::Key_1: - if (_recentlyLoadedScripts.size() > 0) { - Application::getInstance()->loadScript(_recentlyLoadedScripts.at(0)); - } + loadScriptNumber = 1; break; case Qt::Key_2: - if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 2) { - Application::getInstance()->loadScript(_recentlyLoadedScripts.at(1)); - } + loadScriptNumber = 2; break; case Qt::Key_3: - if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 3) { - Application::getInstance()->loadScript(_recentlyLoadedScripts.at(2)); - } + loadScriptNumber = 3; break; case Qt::Key_4: - if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 4) { - Application::getInstance()->loadScript(_recentlyLoadedScripts.at(3)); - } + loadScriptNumber = 4; break; + case Qt::Key_5: - if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 5) { - Application::getInstance()->loadScript(_recentlyLoadedScripts.at(4)); - } + loadScriptNumber = 5; break; case Qt::Key_6: - if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 6) { - Application::getInstance()->loadScript(_recentlyLoadedScripts.at(5)); - } + loadScriptNumber = 6; break; case Qt::Key_7: - if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 7) { - Application::getInstance()->loadScript(_recentlyLoadedScripts.at(6)); - } + loadScriptNumber = 7; break; case Qt::Key_8: - if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 8) { - Application::getInstance()->loadScript(_recentlyLoadedScripts.at(7)); - } + loadScriptNumber = 8; break; case Qt::Key_9: - if (_recentlyLoadedScripts.size() > 0 && _recentlyLoadedScripts.size() >= 9) { - Application::getInstance()->loadScript(_recentlyLoadedScripts.at(8)); - } + loadScriptNumber = 9; break; default: break; } + if (loadScriptNumber > 0) { + if (_recentlyLoadedScripts.size() >= loadScriptNumber) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(loadScriptNumber - 1)); + } + } FramelessDialog::keyPressEvent(e); } From 792ab7e17e011c2e8163d4c3a19ef24cf4093fab Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 25 Apr 2014 15:57:10 -0700 Subject: [PATCH 22/37] Update icon for Load Script button --- interface/resources/images/plus-white.svg | 7 +++++++ interface/src/ui/RunningScriptsWidget.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 interface/resources/images/plus-white.svg diff --git a/interface/resources/images/plus-white.svg b/interface/resources/images/plus-white.svg new file mode 100644 index 0000000000..8bd089881e --- /dev/null +++ b/interface/resources/images/plus-white.svg @@ -0,0 +1,7 @@ + + + + + + diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 3d3aa66e92..d66fba2aba 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -32,7 +32,7 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget *parent) : ui->hideWidgetButton->setIcon(QIcon(Application::resourcesPath() + "images/close.svg")); ui->reloadAllButton->setIcon(QIcon(Application::resourcesPath() + "images/reload.svg")); ui->stopAllButton->setIcon(QIcon(Application::resourcesPath() + "images/stop.svg")); - ui->loadScriptButton->setIcon(QIcon(Application::resourcesPath() + "images/plus.svg")); + ui->loadScriptButton->setIcon(QIcon(Application::resourcesPath() + "images/plus-white.svg")); _runningScriptsTable = new ScriptsTableWidget(ui->runningScriptsTableWidget); _runningScriptsTable->setColumnCount(2); From f889cef3aa310525198fa699987a053f6782607d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 25 Apr 2014 16:15:11 -0700 Subject: [PATCH 23/37] Remove the ability to drag the RunningScripts window --- interface/src/ui/RunningScriptsWidget.cpp | 37 +---------------------- interface/src/ui/RunningScriptsWidget.h | 5 --- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index d66fba2aba..b27d99aaae 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -21,9 +21,7 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget *parent) : FramelessDialog(parent, 0, POSITION_LEFT), - ui(new Ui::RunningScriptsWidget), - _mousePressed(false), - _mousePosition(QPoint()) + ui(new Ui::RunningScriptsWidget) { ui->setupUi(this); @@ -106,39 +104,6 @@ void RunningScriptsWidget::setRunningScripts(const QStringList& list) createRecentlyLoadedScriptsTable(); } -void RunningScriptsWidget::mousePressEvent(QMouseEvent *e) -{ - if (e->button() == Qt::LeftButton) { - _mousePressed = true; - _mousePosition = e->pos(); - } else { - _mousePressed = false; - _mousePosition = QPoint(); - } - FramelessDialog::mousePressEvent(e); -} - -void RunningScriptsWidget::mouseMoveEvent(QMouseEvent *e) -{ - if (_mousePressed) { - QPoint newPosition = mapToParent(e->pos() - _mousePosition); - if (newPosition.x() >= _boundary.x() && - newPosition.x() <= (_boundary.width() - width())) { - move(newPosition.x(), _boundary.y()); - } - } - FramelessDialog::mouseMoveEvent(e); -} - -void RunningScriptsWidget::mouseReleaseEvent(QMouseEvent *e) -{ - if (e->button() == Qt::LeftButton) { - _mousePressed = false; - _mousePosition = QPoint(); - } - FramelessDialog::mouseReleaseEvent(e); -} - void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) { int loadScriptNumber = -1; diff --git a/interface/src/ui/RunningScriptsWidget.h b/interface/src/ui/RunningScriptsWidget.h index a4ee2fe57f..8f82df9a5e 100644 --- a/interface/src/ui/RunningScriptsWidget.h +++ b/interface/src/ui/RunningScriptsWidget.h @@ -32,9 +32,6 @@ signals: void stopScriptName(const QString& name); protected: - virtual void mousePressEvent(QMouseEvent *e); - virtual void mouseMoveEvent(QMouseEvent *e); - virtual void mouseReleaseEvent(QMouseEvent *e); virtual void keyPressEvent(QKeyEvent *e); virtual void paintEvent(QPaintEvent *); @@ -53,8 +50,6 @@ private: QStringList _recentlyLoadedScripts; QString _lastStoppedScript; QRect _boundary; - bool _mousePressed; - QPoint _mousePosition; void createRecentlyLoadedScriptsTable(); }; From 8686fecdaddf89ab6a079eb6baa868504a349329 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 28 Apr 2014 16:08:26 -0700 Subject: [PATCH 24/37] Switch OctreeSceneStats to quintX --- libraries/octree/src/OctreeSceneStats.cpp | 111 +++++++++------- libraries/octree/src/OctreeSceneStats.h | 153 +++++++++++----------- 2 files changed, 143 insertions(+), 121 deletions(-) diff --git a/libraries/octree/src/OctreeSceneStats.cpp b/libraries/octree/src/OctreeSceneStats.cpp index e7d34680a7..9b1a978447 100644 --- a/libraries/octree/src/OctreeSceneStats.cpp +++ b/libraries/octree/src/OctreeSceneStats.cpp @@ -657,40 +657,40 @@ void OctreeSceneStats::printDebugDetails() { qDebug(" moving: %s", debug::valueOf(_isMoving)); qDebug(); qDebug(" packets: %d", _packets); - qDebug(" bytes : %ld", _bytes); + qDebug(" bytes : %ld", (long int)_bytes); qDebug(); - qDebug(" total elements : %lu", _totalElements ); - qDebug(" internal : %lu", _totalInternal ); - qDebug(" leaves : %lu", _totalLeaves ); - qDebug(" traversed : %lu", _traversed ); - qDebug(" internal : %lu", _internal ); - qDebug(" leaves : %lu", _leaves ); - qDebug(" skipped distance : %lu", _skippedDistance ); - qDebug(" internal : %lu", _internalSkippedDistance ); - qDebug(" leaves : %lu", _leavesSkippedDistance ); - qDebug(" skipped out of view : %lu", _skippedOutOfView ); - qDebug(" internal : %lu", _internalSkippedOutOfView ); - qDebug(" leaves : %lu", _leavesSkippedOutOfView ); - qDebug(" skipped was in view : %lu", _skippedWasInView ); - qDebug(" internal : %lu", _internalSkippedWasInView ); - qDebug(" leaves : %lu", _leavesSkippedWasInView ); - qDebug(" skipped no change : %lu", _skippedNoChange ); - qDebug(" internal : %lu", _internalSkippedNoChange ); - qDebug(" leaves : %lu", _leavesSkippedNoChange ); - qDebug(" skipped occluded : %lu", _skippedOccluded ); - qDebug(" internal : %lu", _internalSkippedOccluded ); - qDebug(" leaves : %lu", _leavesSkippedOccluded ); + qDebug(" total elements : %lu", (long unsigned int)_totalElements ); + qDebug(" internal : %lu", (long unsigned int)_totalInternal ); + qDebug(" leaves : %lu", (long unsigned int)_totalLeaves ); + qDebug(" traversed : %lu", (long unsigned int)_traversed ); + qDebug(" internal : %lu", (long unsigned int)_internal ); + qDebug(" leaves : %lu", (long unsigned int)_leaves ); + qDebug(" skipped distance : %lu", (long unsigned int)_skippedDistance ); + qDebug(" internal : %lu", (long unsigned int)_internalSkippedDistance ); + qDebug(" leaves : %lu", (long unsigned int)_leavesSkippedDistance ); + qDebug(" skipped out of view : %lu", (long unsigned int)_skippedOutOfView ); + qDebug(" internal : %lu", (long unsigned int)_internalSkippedOutOfView ); + qDebug(" leaves : %lu", (long unsigned int)_leavesSkippedOutOfView ); + qDebug(" skipped was in view : %lu", (long unsigned int)_skippedWasInView ); + qDebug(" internal : %lu", (long unsigned int)_internalSkippedWasInView ); + qDebug(" leaves : %lu", (long unsigned int)_leavesSkippedWasInView ); + qDebug(" skipped no change : %lu", (long unsigned int)_skippedNoChange ); + qDebug(" internal : %lu", (long unsigned int)_internalSkippedNoChange ); + qDebug(" leaves : %lu", (long unsigned int)_leavesSkippedNoChange ); + qDebug(" skipped occluded : %lu", (long unsigned int)_skippedOccluded ); + qDebug(" internal : %lu", (long unsigned int)_internalSkippedOccluded ); + qDebug(" leaves : %lu", (long unsigned int)_leavesSkippedOccluded ); qDebug(); - qDebug(" color sent : %lu", _colorSent ); - qDebug(" internal : %lu", _internalColorSent ); - qDebug(" leaves : %lu", _leavesColorSent ); - qDebug(" Didn't Fit : %lu", _didntFit ); - qDebug(" internal : %lu", _internalDidntFit ); - qDebug(" leaves : %lu", _leavesDidntFit ); - qDebug(" color bits : %lu", _colorBitsWritten ); - qDebug(" exists bits : %lu", _existsBitsWritten ); - qDebug(" in packet bit : %lu", _existsInPacketBitsWritten); - qDebug(" trees removed : %lu", _treesRemoved ); + qDebug(" color sent : %lu", (long unsigned int)_colorSent ); + qDebug(" internal : %lu", (long unsigned int)_internalColorSent ); + qDebug(" leaves : %lu", (long unsigned int)_leavesColorSent ); + qDebug(" Didn't Fit : %lu", (long unsigned int)_didntFit ); + qDebug(" internal : %lu", (long unsigned int)_internalDidntFit ); + qDebug(" leaves : %lu", (long unsigned int)_leavesDidntFit ); + qDebug(" color bits : %lu", (long unsigned int)_colorBitsWritten ); + qDebug(" exists bits : %lu", (long unsigned int)_existsBitsWritten ); + qDebug(" in packet bit : %lu", (long unsigned int)_existsInPacketBitsWritten); + qDebug(" trees removed : %lu", (long unsigned int)_treesRemoved ); } OctreeSceneStats::ItemInfo OctreeSceneStats::_ITEMS[] = { @@ -732,12 +732,14 @@ const char* OctreeSceneStats::getItemValue(Item item) { case ITEM_PACKETS: { float elapsedSecs = ((float)_elapsed / (float)USECS_PER_SECOND); calculatedKBPS = elapsedSecs == 0 ? 0 : ((_bytes * 8) / elapsedSecs) / 1000; - sprintf(_itemValueBuffer, "%d packets %lu bytes (%d kbps)", _packets, _bytes, calculatedKBPS); + sprintf(_itemValueBuffer, "%d packets %lu bytes (%d kbps)", _packets, (long unsigned int)_bytes, calculatedKBPS); break; } case ITEM_VOXELS_SERVER: { - sprintf(_itemValueBuffer, "%lu total %lu internal %lu leaves", - _totalElements, _totalInternal, _totalLeaves); + sprintf(_itemValueBuffer, "%lu total %lu internal %lu leaves", + (long unsigned int)_totalElements, + (long unsigned int)_totalInternal, + (long unsigned int)_totalLeaves); break; } case ITEM_VOXELS: { @@ -745,12 +747,14 @@ const char* OctreeSceneStats::getItemValue(Item item) { float calculatedBPV = total == 0 ? 0 : (_bytes * 8) / total; float averageBPV = _bitsPerOctreeAverage.getAverage(); sprintf(_itemValueBuffer, "%lu (%.2f bits/octree Average: %.2f bits/octree) %lu internal %lu leaves", - total, calculatedBPV, averageBPV, _existsInPacketBitsWritten, _colorSent); + total, calculatedBPV, averageBPV, + (long unsigned int)_existsInPacketBitsWritten, + (long unsigned int)_colorSent); break; } case ITEM_TRAVERSED: { sprintf(_itemValueBuffer, "%lu total %lu internal %lu leaves", - _traversed, _internal, _leaves); + (long unsigned int)_traversed, (long unsigned int)_internal, (long unsigned int)_leaves); break; } case ITEM_SKIPPED: { @@ -769,42 +773,59 @@ const char* OctreeSceneStats::getItemValue(Item item) { } case ITEM_SKIPPED_DISTANCE: { sprintf(_itemValueBuffer, "%lu total %lu internal %lu leaves", - _skippedDistance, _internalSkippedDistance, _leavesSkippedDistance); + (long unsigned int)_skippedDistance, + (long unsigned int)_internalSkippedDistance, + (long unsigned int)_leavesSkippedDistance); break; } case ITEM_SKIPPED_OUT_OF_VIEW: { sprintf(_itemValueBuffer, "%lu total %lu internal %lu leaves", - _skippedOutOfView, _internalSkippedOutOfView, _leavesSkippedOutOfView); + (long unsigned int)_skippedOutOfView, + (long unsigned int)_internalSkippedOutOfView, + (long unsigned int)_leavesSkippedOutOfView); break; } case ITEM_SKIPPED_WAS_IN_VIEW: { sprintf(_itemValueBuffer, "%lu total %lu internal %lu leaves", - _skippedWasInView, _internalSkippedWasInView, _leavesSkippedWasInView); + (long unsigned int)_skippedWasInView, + (long unsigned int)_internalSkippedWasInView, + (long unsigned int)_leavesSkippedWasInView); break; } case ITEM_SKIPPED_NO_CHANGE: { sprintf(_itemValueBuffer, "%lu total %lu internal %lu leaves", - _skippedNoChange, _internalSkippedNoChange, _leavesSkippedNoChange); + (long unsigned int)_skippedNoChange, + (long unsigned int)_internalSkippedNoChange, + (long unsigned int)_leavesSkippedNoChange); break; } case ITEM_SKIPPED_OCCLUDED: { sprintf(_itemValueBuffer, "%lu total %lu internal %lu leaves", - _skippedOccluded, _internalSkippedOccluded, _leavesSkippedOccluded); + (long unsigned int)_skippedOccluded, + (long unsigned int)_internalSkippedOccluded, + (long unsigned int)_leavesSkippedOccluded); break; } case ITEM_COLORS: { sprintf(_itemValueBuffer, "%lu total %lu internal %lu leaves", - _colorSent, _internalColorSent, _leavesColorSent); + (long unsigned int)_colorSent, + (long unsigned int)_internalColorSent, + (long unsigned int)_leavesColorSent); break; } case ITEM_DIDNT_FIT: { sprintf(_itemValueBuffer, "%lu total %lu internal %lu leaves (removed: %lu)", - _didntFit, _internalDidntFit, _leavesDidntFit, _treesRemoved); + (long unsigned int)_didntFit, + (long unsigned int)_internalDidntFit, + (long unsigned int)_leavesDidntFit, + (long unsigned int)_treesRemoved); break; } case ITEM_BITS: { sprintf(_itemValueBuffer, "colors: %lu, exists: %lu, in packets: %lu", - _colorBitsWritten, _existsBitsWritten, _existsInPacketBitsWritten); + (long unsigned int)_colorBitsWritten, + (long unsigned int)_existsBitsWritten, + (long unsigned int)_existsInPacketBitsWritten); break; } case ITEM_MODE: { diff --git a/libraries/octree/src/OctreeSceneStats.h b/libraries/octree/src/OctreeSceneStats.h index 140e33aedf..e451da0308 100644 --- a/libraries/octree/src/OctreeSceneStats.h +++ b/libraries/octree/src/OctreeSceneStats.h @@ -88,10 +88,10 @@ public: void childBitsRemoved(bool includesExistsBits, bool includesColors); /// Pack the details of the statistics into a buffer for sending as a network packet - int packIntoMessage(unsigned char* destinationBuffer, int availableBytes); + int packIntoMessage(quint8* destinationBuffer, int availableBytes); /// Unpack the details of the statistics from a buffer typically received as a network packet - int unpackFromMessage(const unsigned char* sourceBuffer, int availableBytes); + int unpackFromMessage(const quint8* sourceBuffer, int availableBytes); /// Indicates that a scene has been completed and the statistics are ready to be sent bool isReadyToSend() const { return _isReadyToSend; } @@ -99,8 +99,8 @@ public: /// Mark that the scene statistics have been sent void markAsSent() { _isReadyToSend = false; } - unsigned char* getStatsMessage() { return &_statsMessage[0]; } - int getStatsMessageLength() const { return _statsMessageLength; } + quint8* getStatsMessage() { return &_statsMessage[0]; } + qint32 getStatsMessageLength() const { return _statsMessageLength; } /// List of various items tracked by OctreeSceneStats which can be accessed via getItemInfo() and getItemValue() enum Item { @@ -140,36 +140,36 @@ public: const char* getItemValue(Item item); /// Returns OctCode for root element of the jurisdiction of this particular octree server - unsigned char* getJurisdictionRoot() const { return _jurisdictionRoot; } + quint8* getJurisdictionRoot() const { return _jurisdictionRoot; } /// Returns list of OctCodes for end elements of the jurisdiction of this particular octree server - const std::vector& getJurisdictionEndNodes() const { return _jurisdictionEndNodes; } + const std::vector& getJurisdictionEndNodes() const { return _jurisdictionEndNodes; } bool isMoving() const { return _isMoving; }; - unsigned long getTotalElements() const { return _totalElements; } - unsigned long getTotalInternal() const { return _totalInternal; } - unsigned long getTotalLeaves() const { return _totalLeaves; } - unsigned long getTotalEncodeTime() const { return _totalEncodeTime; } - unsigned long getElapsedTime() const { return _elapsed; } + quint64 getTotalElements() const { return _totalElements; } + quint64 getTotalInternal() const { return _totalInternal; } + quint64 getTotalLeaves() const { return _totalLeaves; } + quint64 getTotalEncodeTime() const { return _totalEncodeTime; } + quint64 getElapsedTime() const { return _elapsed; } - unsigned long getLastFullElapsedTime() const { return _lastFullElapsed; } - unsigned long getLastFullTotalEncodeTime() const { return _lastFullTotalEncodeTime; } - unsigned int getLastFullTotalPackets() const { return _lastFullTotalPackets; } - unsigned long getLastFullTotalBytes() const { return _lastFullTotalBytes; } + quint64 getLastFullElapsedTime() const { return _lastFullElapsed; } + quint64 getLastFullTotalEncodeTime() const { return _lastFullTotalEncodeTime; } + quint32 getLastFullTotalPackets() const { return _lastFullTotalPackets; } + quint64 getLastFullTotalBytes() const { return _lastFullTotalBytes; } // Used in client implementations to track individual octree packets void trackIncomingOctreePacket(const QByteArray& packet, bool wasStatsPacket, int nodeClockSkewUsec); - unsigned int getIncomingPackets() const { return _incomingPacket; } - unsigned long getIncomingBytes() const { return _incomingBytes; } - unsigned long getIncomingWastedBytes() const { return _incomingWastedBytes; } - unsigned int getIncomingOutOfOrder() const { return _incomingLate + _incomingEarly; } - unsigned int getIncomingLikelyLost() const { return _incomingLikelyLost; } - unsigned int getIncomingRecovered() const { return _incomingRecovered; } - unsigned int getIncomingEarly() const { return _incomingEarly; } - unsigned int getIncomingLate() const { return _incomingLate; } - unsigned int getIncomingReallyLate() const { return _incomingReallyLate; } - unsigned int getIncomingPossibleDuplicate() const { return _incomingPossibleDuplicate; } + quint32 getIncomingPackets() const { return _incomingPacket; } + quint64 getIncomingBytes() const { return _incomingBytes; } + quint64 getIncomingWastedBytes() const { return _incomingWastedBytes; } + quint32 getIncomingOutOfOrder() const { return _incomingLate + _incomingEarly; } + quint32 getIncomingLikelyLost() const { return _incomingLikelyLost; } + quint32 getIncomingRecovered() const { return _incomingRecovered; } + quint32 getIncomingEarly() const { return _incomingEarly; } + quint32 getIncomingLate() const { return _incomingLate; } + quint32 getIncomingReallyLate() const { return _incomingReallyLate; } + quint32 getIncomingPossibleDuplicate() const { return _incomingPossibleDuplicate; } float getIncomingFlightTimeAverage() { return _incomingFlightTimeAverage.getAverage(); } private: @@ -177,8 +177,9 @@ private: void copyFromOther(const OctreeSceneStats& other); bool _isReadyToSend; - unsigned char _statsMessage[MAX_PACKET_SIZE]; - int _statsMessageLength; + quint8 _statsMessage[MAX_PACKET_SIZE]; + + qint32 _statsMessageLength; // scene timing data in usecs bool _isStarted; @@ -188,8 +189,8 @@ private: quint64 _lastFullElapsed; quint64 _lastFullTotalEncodeTime; - unsigned int _lastFullTotalPackets; - unsigned long _lastFullTotalBytes; + quint32 _lastFullTotalPackets; + quint64 _lastFullTotalBytes; SimpleMovingAverage _elapsedAverage; SimpleMovingAverage _bitsPerOctreeAverage; @@ -198,46 +199,46 @@ private: quint64 _encodeStart; // scene octree related data - unsigned long _totalElements; - unsigned long _totalInternal; - unsigned long _totalLeaves; + quint64 _totalElements; + quint64 _totalInternal; + quint64 _totalLeaves; - unsigned long _traversed; - unsigned long _internal; - unsigned long _leaves; + quint64 _traversed; + quint64 _internal; + quint64 _leaves; - unsigned long _skippedDistance; - unsigned long _internalSkippedDistance; - unsigned long _leavesSkippedDistance; + quint64 _skippedDistance; + quint64 _internalSkippedDistance; + quint64 _leavesSkippedDistance; - unsigned long _skippedOutOfView; - unsigned long _internalSkippedOutOfView; - unsigned long _leavesSkippedOutOfView; + quint64 _skippedOutOfView; + quint64 _internalSkippedOutOfView; + quint64 _leavesSkippedOutOfView; - unsigned long _skippedWasInView; - unsigned long _internalSkippedWasInView; - unsigned long _leavesSkippedWasInView; + quint64 _skippedWasInView; + quint64 _internalSkippedWasInView; + quint64 _leavesSkippedWasInView; - unsigned long _skippedNoChange; - unsigned long _internalSkippedNoChange; - unsigned long _leavesSkippedNoChange; + quint64 _skippedNoChange; + quint64 _internalSkippedNoChange; + quint64 _leavesSkippedNoChange; - unsigned long _skippedOccluded; - unsigned long _internalSkippedOccluded; - unsigned long _leavesSkippedOccluded; + quint64 _skippedOccluded; + quint64 _internalSkippedOccluded; + quint64 _leavesSkippedOccluded; - unsigned long _colorSent; - unsigned long _internalColorSent; - unsigned long _leavesColorSent; + quint64 _colorSent; + quint64 _internalColorSent; + quint64 _leavesColorSent; - unsigned long _didntFit; - unsigned long _internalDidntFit; - unsigned long _leavesDidntFit; + quint64 _didntFit; + quint64 _internalDidntFit; + quint64 _leavesDidntFit; - unsigned long _colorBitsWritten; - unsigned long _existsBitsWritten; - unsigned long _existsInPacketBitsWritten; - unsigned long _treesRemoved; + quint64 _colorBitsWritten; + quint64 _existsBitsWritten; + quint64 _existsInPacketBitsWritten; + quint64 _treesRemoved; // Accounting Notes: // @@ -255,22 +256,22 @@ private: // // scene network related data - unsigned int _packets; - unsigned long _bytes; - unsigned int _passes; + quint32 _packets; + quint64 _bytes; + quint32 _passes; // incoming packets stats - unsigned int _incomingPacket; - unsigned long _incomingBytes; - unsigned long _incomingWastedBytes; + quint32 _incomingPacket; + quint64 _incomingBytes; + quint64 _incomingWastedBytes; - uint16_t _incomingLastSequence; /// last incoming sequence number - unsigned int _incomingLikelyLost; /// count of packets likely lost, may be off by _incomingReallyLate count - unsigned int _incomingRecovered; /// packets that were late, and we had in our missing list, we consider recovered - unsigned int _incomingEarly; /// out of order earlier than expected - unsigned int _incomingLate; /// out of order later than expected - unsigned int _incomingReallyLate; /// out of order and later than MAX_MISSING_SEQUENCE_OLD_AGE late - unsigned int _incomingPossibleDuplicate; /// out of order possibly a duplicate + quint16 _incomingLastSequence; /// last incoming sequence number + quint32 _incomingLikelyLost; /// count of packets likely lost, may be off by _incomingReallyLate count + quint32 _incomingRecovered; /// packets that were late, and we had in our missing list, we consider recovered + quint32 _incomingEarly; /// out of order earlier than expected + quint32 _incomingLate; /// out of order later than expected + quint32 _incomingReallyLate; /// out of order and later than MAX_MISSING_SEQUENCE_OLD_AGE late + quint32 _incomingPossibleDuplicate; /// out of order possibly a duplicate QSet _missingSequenceNumbers; SimpleMovingAverage _incomingFlightTimeAverage; @@ -280,11 +281,11 @@ private: static ItemInfo _ITEMS[]; - static int const MAX_ITEM_VALUE_LENGTH = 128; + static const int MAX_ITEM_VALUE_LENGTH = 128; char _itemValueBuffer[MAX_ITEM_VALUE_LENGTH]; - unsigned char* _jurisdictionRoot; - std::vector _jurisdictionEndNodes; + quint8* _jurisdictionRoot; + std::vector _jurisdictionEndNodes; }; /// Map between element IDs and their reported OctreeSceneStats. Typically used by classes that need to know which elements sent From 6595b29a4ffde5e8d75215913d7185a0b7029e8e Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 29 Apr 2014 10:55:30 -0700 Subject: [PATCH 25/37] More bug tracking --- libraries/shared/src/SharedUtil.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index c65b7505ee..5cfd8961ec 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -615,7 +615,7 @@ int unpackClipValueFromTwoByte(const unsigned char* buffer, float& clipValue) { } int packFloatToByte(unsigned char* buffer, float value, float scaleBy) { - unsigned char holder; + quint8 holder; const float CONVERSION_RATIO = (255 / scaleBy); holder = floorf(value * CONVERSION_RATIO); memcpy(buffer, &holder, sizeof(holder)); @@ -623,7 +623,7 @@ int packFloatToByte(unsigned char* buffer, float value, float scaleBy) { } int unpackFloatFromByte(const unsigned char* buffer, float& value, float scaleBy) { - unsigned char holder; + quint8 holder; memcpy(&holder, buffer, sizeof(holder)); value = ((float)holder / (float) 255) * scaleBy; return sizeof(holder); From f74bd491d6197f576798ac843c0cd8e1eff6f4e7 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 29 Apr 2014 12:48:50 -0700 Subject: [PATCH 26/37] CR --- libraries/octree/src/OctreeSceneStats.cpp | 114 +++++++++++----------- libraries/octree/src/OctreeSceneStats.h | 18 ++-- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/libraries/octree/src/OctreeSceneStats.cpp b/libraries/octree/src/OctreeSceneStats.cpp index 9b1a978447..1dc1459771 100644 --- a/libraries/octree/src/OctreeSceneStats.cpp +++ b/libraries/octree/src/OctreeSceneStats.cpp @@ -646,70 +646,70 @@ int OctreeSceneStats::unpackFromMessage(const unsigned char* sourceBuffer, int a void OctreeSceneStats::printDebugDetails() { - qDebug("\n------------------------------"); - qDebug("OctreeSceneStats:"); - qDebug(" start : %llu", (long long unsigned int)_start); - qDebug(" end : %llu", (long long unsigned int)_end); - qDebug(" elapsed : %llu", (long long unsigned int)_elapsed); - qDebug(" encoding : %llu", (long long unsigned int)_totalEncodeTime); + qDebug() << "\n------------------------------"; + qDebug() << "OctreeSceneStats:"; + qDebug() << "start: " << _start; + qDebug() << "end: " << _end; + qDebug() << "elapsed: " << _elapsed; + qDebug() << "encoding: " << _totalEncodeTime; qDebug(); - qDebug(" full scene: %s", debug::valueOf(_isFullScene)); - qDebug(" moving: %s", debug::valueOf(_isMoving)); + qDebug() << "full scene: " << debug::valueOf(_isFullScene); + qDebug() << "moving: " << debug::valueOf(_isMoving); qDebug(); - qDebug(" packets: %d", _packets); - qDebug(" bytes : %ld", (long int)_bytes); + qDebug() << "packets: " << _packets; + qDebug() << "bytes: " << _bytes; qDebug(); - qDebug(" total elements : %lu", (long unsigned int)_totalElements ); - qDebug(" internal : %lu", (long unsigned int)_totalInternal ); - qDebug(" leaves : %lu", (long unsigned int)_totalLeaves ); - qDebug(" traversed : %lu", (long unsigned int)_traversed ); - qDebug(" internal : %lu", (long unsigned int)_internal ); - qDebug(" leaves : %lu", (long unsigned int)_leaves ); - qDebug(" skipped distance : %lu", (long unsigned int)_skippedDistance ); - qDebug(" internal : %lu", (long unsigned int)_internalSkippedDistance ); - qDebug(" leaves : %lu", (long unsigned int)_leavesSkippedDistance ); - qDebug(" skipped out of view : %lu", (long unsigned int)_skippedOutOfView ); - qDebug(" internal : %lu", (long unsigned int)_internalSkippedOutOfView ); - qDebug(" leaves : %lu", (long unsigned int)_leavesSkippedOutOfView ); - qDebug(" skipped was in view : %lu", (long unsigned int)_skippedWasInView ); - qDebug(" internal : %lu", (long unsigned int)_internalSkippedWasInView ); - qDebug(" leaves : %lu", (long unsigned int)_leavesSkippedWasInView ); - qDebug(" skipped no change : %lu", (long unsigned int)_skippedNoChange ); - qDebug(" internal : %lu", (long unsigned int)_internalSkippedNoChange ); - qDebug(" leaves : %lu", (long unsigned int)_leavesSkippedNoChange ); - qDebug(" skipped occluded : %lu", (long unsigned int)_skippedOccluded ); - qDebug(" internal : %lu", (long unsigned int)_internalSkippedOccluded ); - qDebug(" leaves : %lu", (long unsigned int)_leavesSkippedOccluded ); + qDebug() << "total elements: " << _totalElements; + qDebug() << "internal: " << _totalInternal; + qDebug() << "leaves: " << _totalLeaves; + qDebug() << "traversed: " << _traversed; + qDebug() << "internal: " << _internal; + qDebug() << "leaves: " << _leaves; + qDebug() << "skipped distance: " << _skippedDistance; + qDebug() << "internal: " << _internalSkippedDistance; + qDebug() << "leaves: " << _leavesSkippedDistance; + qDebug() << "skipped out of view: " << _skippedOutOfView; + qDebug() << "internal: " << _internalSkippedOutOfView; + qDebug() << "leaves: " << _leavesSkippedOutOfView; + qDebug() << "skipped was in view: " << _skippedWasInView; + qDebug() << "internal: " << _internalSkippedWasInView; + qDebug() << "leaves: " << _leavesSkippedWasInView; + qDebug() << "skipped no change: " << _skippedNoChange; + qDebug() << "internal: " << _internalSkippedNoChange; + qDebug() << "leaves: " << _leavesSkippedNoChange; + qDebug() << "skipped occluded: " << _skippedOccluded; + qDebug() << "internal: " << _internalSkippedOccluded; + qDebug() << "leaves: " << _leavesSkippedOccluded; qDebug(); - qDebug(" color sent : %lu", (long unsigned int)_colorSent ); - qDebug(" internal : %lu", (long unsigned int)_internalColorSent ); - qDebug(" leaves : %lu", (long unsigned int)_leavesColorSent ); - qDebug(" Didn't Fit : %lu", (long unsigned int)_didntFit ); - qDebug(" internal : %lu", (long unsigned int)_internalDidntFit ); - qDebug(" leaves : %lu", (long unsigned int)_leavesDidntFit ); - qDebug(" color bits : %lu", (long unsigned int)_colorBitsWritten ); - qDebug(" exists bits : %lu", (long unsigned int)_existsBitsWritten ); - qDebug(" in packet bit : %lu", (long unsigned int)_existsInPacketBitsWritten); - qDebug(" trees removed : %lu", (long unsigned int)_treesRemoved ); + qDebug() << "color sent: " << _colorSent; + qDebug() << "internal: " << _internalColorSent; + qDebug() << "leaves: " << _leavesColorSent; + qDebug() << "Didn't Fit: " << _didntFit; + qDebug() << "internal: " << _internalDidntFit; + qDebug() << "leaves: " << _leavesDidntFit; + qDebug() << "color bits: " << _colorBitsWritten; + qDebug() << "exists bits: " << _existsBitsWritten; + qDebug() << "in packet bit: " << _existsInPacketBitsWritten; + qDebug() << "trees removed: " << _treesRemoved; } OctreeSceneStats::ItemInfo OctreeSceneStats::_ITEMS[] = { - { "Elapsed" , GREENISH , 2 , "Elapsed,fps" }, - { "Encode" , YELLOWISH , 2 , "Time,fps" }, - { "Network" , GREYISH , 3 , "Packets,Bytes,KBPS" }, - { "Octrees on Server" , GREENISH , 3 , "Total,Internal,Leaves" }, - { "Octrees Sent" , YELLOWISH , 5 , "Total,Bits/Octree,Avg Bits/Octree,Internal,Leaves" }, - { "Colors Sent" , GREYISH , 3 , "Total,Internal,Leaves" }, - { "Bitmasks Sent" , GREENISH , 3 , "Colors,Exists,In Packets" }, - { "Traversed" , YELLOWISH , 3 , "Total,Internal,Leaves" }, - { "Skipped - Total" , GREYISH , 3 , "Total,Internal,Leaves" }, - { "Skipped - Distance" , GREENISH , 3 , "Total,Internal,Leaves" }, - { "Skipped - Out of View", YELLOWISH , 3 , "Total,Internal,Leaves" }, - { "Skipped - Was in View", GREYISH , 3 , "Total,Internal,Leaves" }, - { "Skipped - No Change" , GREENISH , 3 , "Total,Internal,Leaves" }, - { "Skipped - Occluded" , YELLOWISH , 3 , "Total,Internal,Leaves" }, - { "Didn't fit in packet" , GREYISH , 4 , "Total,Internal,Leaves,Removed" }, - { "Mode" , GREENISH , 4 , "Moving,Stationary,Partial,Full" }, + { "Elapsed", GREENISH, 2, "Elapsed,fps" }, + { "Encode", YELLOWISH, 2, "Time,fps" }, + { "Network", GREYISH, 3, "Packets,Bytes,KBPS" }, + { "Octrees on Server", GREENISH, 3, "Total,Internal,Leaves" }, + { "Octrees Sent", YELLOWISH, 5, "Total,Bits/Octree,Avg Bits/Octree,Internal,Leaves" }, + { "Colors Sent", GREYISH, 3, "Total,Internal,Leaves" }, + { "Bitmasks Sent", GREENISH, 3, "Colors,Exists,In Packets" }, + { "Traversed", YELLOWISH, 3, "Total,Internal,Leaves" }, + { "Skipped - Total", GREYISH, 3, "Total,Internal,Leaves" }, + { "Skipped - Distance", GREENISH, 3, "Total,Internal,Leaves" }, + { "Skipped - Out of View", YELLOWISH, 3, "Total,Internal,Leaves" }, + { "Skipped - Was in View", GREYISH, 3, "Total,Internal,Leaves" }, + { "Skipped - No Change", GREENISH, 3, "Total,Internal,Leaves" }, + { "Skipped - Occluded", YELLOWISH, 3, "Total,Internal,Leaves" }, + { "Didn't fit in packet", GREYISH, 4, "Total,Internal,Leaves,Removed" }, + { "Mode", GREENISH, 4, "Moving,Stationary,Partial,Full" }, }; const char* OctreeSceneStats::getItemValue(Item item) { diff --git a/libraries/octree/src/OctreeSceneStats.h b/libraries/octree/src/OctreeSceneStats.h index e451da0308..ef22fd7c1c 100644 --- a/libraries/octree/src/OctreeSceneStats.h +++ b/libraries/octree/src/OctreeSceneStats.h @@ -88,10 +88,10 @@ public: void childBitsRemoved(bool includesExistsBits, bool includesColors); /// Pack the details of the statistics into a buffer for sending as a network packet - int packIntoMessage(quint8* destinationBuffer, int availableBytes); + int packIntoMessage(unsigned char* destinationBuffer, int availableBytes); /// Unpack the details of the statistics from a buffer typically received as a network packet - int unpackFromMessage(const quint8* sourceBuffer, int availableBytes); + int unpackFromMessage(const unsigned char* sourceBuffer, int availableBytes); /// Indicates that a scene has been completed and the statistics are ready to be sent bool isReadyToSend() const { return _isReadyToSend; } @@ -99,8 +99,8 @@ public: /// Mark that the scene statistics have been sent void markAsSent() { _isReadyToSend = false; } - quint8* getStatsMessage() { return &_statsMessage[0]; } - qint32 getStatsMessageLength() const { return _statsMessageLength; } + unsigned char* getStatsMessage() { return &_statsMessage[0]; } + int getStatsMessageLength() const { return _statsMessageLength; } /// List of various items tracked by OctreeSceneStats which can be accessed via getItemInfo() and getItemValue() enum Item { @@ -140,10 +140,10 @@ public: const char* getItemValue(Item item); /// Returns OctCode for root element of the jurisdiction of this particular octree server - quint8* getJurisdictionRoot() const { return _jurisdictionRoot; } + unsigned char* getJurisdictionRoot() const { return _jurisdictionRoot; } /// Returns list of OctCodes for end elements of the jurisdiction of this particular octree server - const std::vector& getJurisdictionEndNodes() const { return _jurisdictionEndNodes; } + const std::vector& getJurisdictionEndNodes() const { return _jurisdictionEndNodes; } bool isMoving() const { return _isMoving; }; quint64 getTotalElements() const { return _totalElements; } @@ -177,7 +177,7 @@ private: void copyFromOther(const OctreeSceneStats& other); bool _isReadyToSend; - quint8 _statsMessage[MAX_PACKET_SIZE]; + unsigned char _statsMessage[MAX_PACKET_SIZE]; qint32 _statsMessageLength; @@ -284,8 +284,8 @@ private: static const int MAX_ITEM_VALUE_LENGTH = 128; char _itemValueBuffer[MAX_ITEM_VALUE_LENGTH]; - quint8* _jurisdictionRoot; - std::vector _jurisdictionEndNodes; + unsigned char* _jurisdictionRoot; + std::vector _jurisdictionEndNodes; }; /// Map between element IDs and their reported OctreeSceneStats. Typically used by classes that need to know which elements sent From 49eadac02473b2f7ed413b54df89b1d5d9bcbde2 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 29 Apr 2014 13:52:07 -0700 Subject: [PATCH 27/37] Bumped octree stats packet version --- libraries/networking/src/PacketHeaders.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index 29238220e1..0955759097 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -62,6 +62,8 @@ PacketVersion versionForPacketType(PacketType type) { case PacketTypeVoxelSet: case PacketTypeVoxelSetDestructive: return 1; + case PacketTypeOctreeStats: + return 1; default: return 0; } From 4aa96e1fbe9cbbd2c4bffca3be0c9bff28a7957d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 29 Apr 2014 15:10:28 -0700 Subject: [PATCH 28/37] added support for returning accuracy of ray intersections and other octree tests that can fail due to getting lock --- examples/rayPickExample.js | 6 +++ libraries/octree/src/Octree.cpp | 49 ++++++++++++++++--- libraries/octree/src/Octree.h | 17 ++++--- libraries/script-engine/src/LocalVoxels.cpp | 11 ++++- libraries/script-engine/src/LocalVoxels.h | 11 ++++- libraries/voxels/src/VoxelDetail.cpp | 3 ++ libraries/voxels/src/VoxelDetail.h | 1 + .../voxels/src/VoxelsScriptingInterface.cpp | 13 ++++- .../voxels/src/VoxelsScriptingInterface.h | 30 +++++++----- 9 files changed, 112 insertions(+), 29 deletions(-) diff --git a/examples/rayPickExample.js b/examples/rayPickExample.js index c09a7b1e57..9b08a76a2a 100644 --- a/examples/rayPickExample.js +++ b/examples/rayPickExample.js @@ -19,6 +19,12 @@ function mouseMoveEvent(event) { print("computePickRay direction=" + pickRay.direction.x + ", " + pickRay.direction.y + ", " + pickRay.direction.z); var pickRay = Camera.computePickRay(event.x, event.y); var intersection = Voxels.findRayIntersection(pickRay); + if (!intersection.accurate) { + print(">>> NOTE: intersection not accurate. will try calling Voxels.findRayIntersectionBlocking()"); + intersection = Voxels.findRayIntersectionBlocking(pickRay); + print(">>> AFTER BLOCKING CALL intersection.accurate=" + intersection.accurate); + } + if (intersection.intersects) { print("intersection voxel.red/green/blue=" + intersection.voxel.red + ", " + intersection.voxel.green + ", " + intersection.voxel.blue); diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 5e812c06c3..266447e27e 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -594,8 +594,9 @@ bool findRayIntersectionOp(OctreeElement* node, void* extraData) { } bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - OctreeElement*& node, float& distance, BoxFace& face, Octree::lockType lockType) { - RayArgs args = { origin / (float)(TREE_SCALE), direction, node, distance, face }; + OctreeElement*& node, float& distance, BoxFace& face, + Octree::lockType lockType, bool* accurateResult) { + RayArgs args = { origin / (float)(TREE_SCALE), direction, node, distance, face, false}; bool gotLock = false; if (lockType == Octree::Lock) { @@ -604,6 +605,9 @@ bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direc } else if (lockType == Octree::TryLock) { gotLock = tryLockForRead(); if (!gotLock) { + if (accurateResult) { + *accurateResult = false; // if user asked to accuracy or result, let them know this is inaccurate + } return args.found; // if we wanted to tryLock, and we couldn't then just bail... } } @@ -614,6 +618,9 @@ bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direc unlock(); } + if (accurateResult) { + *accurateResult = true; // if user asked to accuracy or result, let them know this is accurate + } return args.found; } @@ -640,7 +647,8 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) { if (element->hasContent()) { glm::vec3 elementPenetration; if (element->findSpherePenetration(args->center, args->radius, elementPenetration, &args->penetratedObject)) { - // NOTE: it is possible for this penetration accumulation algorithm to produce a final penetration vector with zero length. + // NOTE: it is possible for this penetration accumulation algorithm to produce a + // final penetration vector with zero length. args->penetration = addPenetrations(args->penetration, elementPenetration * (float)(TREE_SCALE)); args->found = true; } @@ -649,7 +657,7 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) { } bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, - void** penetratedObject, Octree::lockType lockType) { + void** penetratedObject, Octree::lockType lockType, bool* accurateResult) { SphereArgs args = { center / (float)(TREE_SCALE), @@ -666,6 +674,9 @@ bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::v } else if (lockType == Octree::TryLock) { gotLock = tryLockForRead(); if (!gotLock) { + if (accurateResult) { + *accurateResult = false; // if user asked to accuracy or result, let them know this is inaccurate + } return args.found; // if we wanted to tryLock, and we couldn't then just bail... } } @@ -679,6 +690,9 @@ bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::v unlock(); } + if (accurateResult) { + *accurateResult = true; // if user asked to accuracy or result, let them know this is accurate + } return args.found; } @@ -741,7 +755,7 @@ bool findShapeCollisionsOp(OctreeElement* node, void* extraData) { } bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, - glm::vec3& penetration, Octree::lockType lockType) { + glm::vec3& penetration, Octree::lockType lockType, bool* accurateResult) { CapsuleArgs args = { start / (float)(TREE_SCALE), @@ -758,6 +772,9 @@ bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end } else if (lockType == Octree::TryLock) { gotLock = tryLockForRead(); if (!gotLock) { + if (accurateResult) { + *accurateResult = false; // if user asked to accuracy or result, let them know this is inaccurate + } return args.found; // if we wanted to tryLock, and we couldn't then just bail... } } @@ -767,10 +784,15 @@ bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end if (gotLock) { unlock(); } + + if (accurateResult) { + *accurateResult = true; // if user asked to accuracy or result, let them know this is accurate + } return args.found; } -bool Octree::findShapeCollisions(const Shape* shape, CollisionList& collisions, Octree::lockType lockType) { +bool Octree::findShapeCollisions(const Shape* shape, CollisionList& collisions, + Octree::lockType lockType, bool* accurateResult) { ShapeArgs args = { shape, collisions, false }; @@ -781,6 +803,9 @@ bool Octree::findShapeCollisions(const Shape* shape, CollisionList& collisions, } else if (lockType == Octree::TryLock) { gotLock = tryLockForRead(); if (!gotLock) { + if (accurateResult) { + *accurateResult = false; // if user asked to accuracy or result, let them know this is inaccurate + } return args.found; // if we wanted to tryLock, and we couldn't then just bail... } } @@ -790,6 +815,10 @@ bool Octree::findShapeCollisions(const Shape* shape, CollisionList& collisions, if (gotLock) { unlock(); } + + if (accurateResult) { + *accurateResult = true; // if user asked to accuracy or result, let them know this is accurate + } return args.found; } @@ -816,7 +845,7 @@ bool getElementEnclosingOperation(OctreeElement* element, void* extraData) { return true; // keep looking } -OctreeElement* Octree::getElementEnclosingPoint(const glm::vec3& point, Octree::lockType lockType) { +OctreeElement* Octree::getElementEnclosingPoint(const glm::vec3& point, Octree::lockType lockType, bool* accurateResult) { GetElementEnclosingArgs args; args.point = point; args.element = NULL; @@ -828,6 +857,9 @@ OctreeElement* Octree::getElementEnclosingPoint(const glm::vec3& point, Octree:: } else if (lockType == Octree::TryLock) { gotLock = tryLockForRead(); if (!gotLock) { + if (accurateResult) { + *accurateResult = false; // if user asked to accuracy or result, let them know this is inaccurate + } return args.element; // if we wanted to tryLock, and we couldn't then just bail... } } @@ -838,6 +870,9 @@ OctreeElement* Octree::getElementEnclosingPoint(const glm::vec3& point, Octree:: unlock(); } + if (accurateResult) { + *accurateResult = false; // if user asked to accuracy or result, let them know this is inaccurate + } return args.element; } diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index a11e73ab04..56e8d9d08c 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -249,17 +249,20 @@ public: } lockType; bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - OctreeElement*& node, float& distance, BoxFace& face, Octree::lockType lockType = Octree::TryLock); + OctreeElement*& node, float& distance, BoxFace& face, + Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL); - bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, - void** penetratedObject = NULL, Octree::lockType lockType = Octree::TryLock); + bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject = NULL, + Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL); - bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, - glm::vec3& penetration, Octree::lockType lockType = Octree::TryLock); + bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration, + Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL); - bool findShapeCollisions(const Shape* shape, CollisionList& collisions, Octree::lockType = Octree::TryLock); + bool findShapeCollisions(const Shape* shape, CollisionList& collisions, + Octree::lockType = Octree::TryLock, bool* accurateResult = NULL); - OctreeElement* getElementEnclosingPoint(const glm::vec3& point, Octree::lockType lockType = Octree::TryLock); + OctreeElement* getElementEnclosingPoint(const glm::vec3& point, + Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL); // Note: this assumes the fileFormat is the HIO individual voxels code files void loadOctreeFile(const char* fileName, bool wantColorRandomizer); diff --git a/libraries/script-engine/src/LocalVoxels.cpp b/libraries/script-engine/src/LocalVoxels.cpp index 1645c229d6..27952b0998 100644 --- a/libraries/script-engine/src/LocalVoxels.cpp +++ b/libraries/script-engine/src/LocalVoxels.cpp @@ -119,10 +119,19 @@ void LocalVoxels::pasteFrom(float x, float y, float z, float scale, const QStrin } RayToVoxelIntersectionResult LocalVoxels::findRayIntersection(const PickRay& ray) { + return findRayIntersectionWorker(ray, Octree::TryLock); +} + +RayToVoxelIntersectionResult LocalVoxels::findRayIntersectionBlocking(const PickRay& ray) { + return findRayIntersectionWorker(ray, Octree::Lock); +} + +RayToVoxelIntersectionResult LocalVoxels::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType) { RayToVoxelIntersectionResult result; if (_tree) { OctreeElement* element; - result.intersects = _tree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face); + result.intersects = _tree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face, + lockType, &result.accurate); if (result.intersects) { VoxelTreeElement* voxel = (VoxelTreeElement*)element; result.voxel.x = voxel->getCorner().x; diff --git a/libraries/script-engine/src/LocalVoxels.h b/libraries/script-engine/src/LocalVoxels.h index c382d35c09..f6f52aa264 100644 --- a/libraries/script-engine/src/LocalVoxels.h +++ b/libraries/script-engine/src/LocalVoxels.h @@ -76,13 +76,22 @@ public: /// \param source LocalVoxels' source tree Q_INVOKABLE void pasteFrom(float x, float y, float z, float scale, const QString source); - /// If the scripting context has visible voxels, this will determine a ray intersection + /// If the scripting context has visible voxels, this will determine a ray intersection, the results + /// may be inaccurate if the engine is unable to access the visible voxels, in which case result.accurate + /// will be false. Q_INVOKABLE RayToVoxelIntersectionResult findRayIntersection(const PickRay& ray); + + /// If the scripting context has visible voxels, this will determine a ray intersection, and will block in + /// order to return an accurate result + Q_INVOKABLE RayToVoxelIntersectionResult findRayIntersectionBlocking(const PickRay& ray); /// returns a voxel space axis aligned vector for the face, useful in doing voxel math Q_INVOKABLE glm::vec3 getFaceVector(const QString& face); private: + /// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode + RayToVoxelIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType); + QString _name; StrongVoxelTreePointer _tree; }; diff --git a/libraries/voxels/src/VoxelDetail.cpp b/libraries/voxels/src/VoxelDetail.cpp index f1855f5f81..c1f7497d18 100644 --- a/libraries/voxels/src/VoxelDetail.cpp +++ b/libraries/voxels/src/VoxelDetail.cpp @@ -41,6 +41,7 @@ void voxelDetailFromScriptValue(const QScriptValue &object, VoxelDetail& voxelDe RayToVoxelIntersectionResult::RayToVoxelIntersectionResult() : intersects(false), + accurate(true), // assume it's accurate voxel(), distance(0), face() @@ -50,6 +51,7 @@ RayToVoxelIntersectionResult::RayToVoxelIntersectionResult() : QScriptValue rayToVoxelIntersectionResultToScriptValue(QScriptEngine* engine, const RayToVoxelIntersectionResult& value) { QScriptValue obj = engine->newObject(); obj.setProperty("intersects", value.intersects); + obj.setProperty("accurate", value.accurate); QScriptValue voxelValue = voxelDetailToScriptValue(engine, value.voxel); obj.setProperty("voxel", voxelValue); obj.setProperty("distance", value.distance); @@ -88,6 +90,7 @@ QScriptValue rayToVoxelIntersectionResultToScriptValue(QScriptEngine* engine, co void rayToVoxelIntersectionResultFromScriptValue(const QScriptValue& object, RayToVoxelIntersectionResult& value) { value.intersects = object.property("intersects").toVariant().toBool(); + value.accurate = object.property("accurate").toVariant().toBool(); QScriptValue voxelValue = object.property("voxel"); if (voxelValue.isValid()) { voxelDetailFromScriptValue(voxelValue, value.voxel); diff --git a/libraries/voxels/src/VoxelDetail.h b/libraries/voxels/src/VoxelDetail.h index d30255bbb1..76657cf10b 100644 --- a/libraries/voxels/src/VoxelDetail.h +++ b/libraries/voxels/src/VoxelDetail.h @@ -39,6 +39,7 @@ class RayToVoxelIntersectionResult { public: RayToVoxelIntersectionResult(); bool intersects; + bool accurate; VoxelDetail voxel; float distance; BoxFace face; diff --git a/libraries/voxels/src/VoxelsScriptingInterface.cpp b/libraries/voxels/src/VoxelsScriptingInterface.cpp index 15503db454..3f69867530 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.cpp +++ b/libraries/voxels/src/VoxelsScriptingInterface.cpp @@ -122,12 +122,21 @@ void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale } } - RayToVoxelIntersectionResult VoxelsScriptingInterface::findRayIntersection(const PickRay& ray) { + return findRayIntersectionWorker(ray, Octree::TryLock); +} + +RayToVoxelIntersectionResult VoxelsScriptingInterface::findRayIntersectionBlocking(const PickRay& ray) { + return findRayIntersectionWorker(ray, Octree::Lock); +} + +RayToVoxelIntersectionResult VoxelsScriptingInterface::findRayIntersectionWorker(const PickRay& ray, + Octree::lockType lockType) { RayToVoxelIntersectionResult result; if (_tree) { OctreeElement* element; - result.intersects = _tree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face); + result.intersects = _tree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face, + lockType, &result.accurate); if (result.intersects) { VoxelTreeElement* voxel = (VoxelTreeElement*)element; result.voxel.x = voxel->getCorner().x; diff --git a/libraries/voxels/src/VoxelsScriptingInterface.h b/libraries/voxels/src/VoxelsScriptingInterface.h index d5322fdc4d..e5f2abf629 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.h +++ b/libraries/voxels/src/VoxelsScriptingInterface.h @@ -35,17 +35,16 @@ public: void setVoxelTree(VoxelTree* tree) { _tree = tree; } void setUndoStack(QUndoStack* undoStack) { _undoStack = undoStack; } -public slots: - +public: /// provide the world scale - const int getTreeScale() const { return TREE_SCALE; } + Q_INVOKABLE const int getTreeScale() const { return TREE_SCALE; } /// checks the local voxel tree for a voxel at the specified location and scale /// \param x the x-coordinate of the voxel (in meter units) /// \param y the y-coordinate of the voxel (in meter units) /// \param z the z-coordinate of the voxel (in meter units) /// \param scale the scale of the voxel (in meter units) - VoxelDetail getVoxelAt(float x, float y, float z, float scale); + Q_INVOKABLE VoxelDetail getVoxelAt(float x, float y, float z, float scale); /// queues the creation of a voxel which will be sent by calling process on the PacketSender /// \param x the x-coordinate of the voxel (in meter units) @@ -55,7 +54,7 @@ public slots: /// \param red the R value for RGB color of voxel /// \param green the G value for RGB color of voxel /// \param blue the B value for RGB color of voxel - void setVoxelNonDestructive(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); + Q_INVOKABLE void setVoxelNonDestructive(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); /// queues the destructive creation of a voxel which will be sent by calling process on the PacketSender /// \param x the x-coordinate of the voxel (in meter units) @@ -65,27 +64,36 @@ public slots: /// \param red the R value for RGB color of voxel /// \param green the G value for RGB color of voxel /// \param blue the B value for RGB color of voxel - void setVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); + Q_INVOKABLE void setVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); /// queues the deletion of a voxel, sent by calling process on the PacketSender /// \param x the x-coordinate of the voxel (in meter units) /// \param y the y-coordinate of the voxel (in meter units) /// \param z the z-coordinate of the voxel (in meter units) /// \param scale the scale of the voxel (in meter units) - void eraseVoxel(float x, float y, float z, float scale); + Q_INVOKABLE void eraseVoxel(float x, float y, float z, float scale); - /// If the scripting context has visible voxels, this will determine a ray intersection - RayToVoxelIntersectionResult findRayIntersection(const PickRay& ray); + /// If the scripting context has visible voxels, this will determine a ray intersection, the results + /// may be inaccurate if the engine is unable to access the visible voxels, in which case result.accurate + /// will be false. + Q_INVOKABLE RayToVoxelIntersectionResult findRayIntersection(const PickRay& ray); + + /// If the scripting context has visible voxels, this will determine a ray intersection, and will block in + /// order to return an accurate result + Q_INVOKABLE RayToVoxelIntersectionResult findRayIntersectionBlocking(const PickRay& ray); /// returns a voxel space axis aligned vector for the face, useful in doing voxel math - glm::vec3 getFaceVector(const QString& face); + Q_INVOKABLE glm::vec3 getFaceVector(const QString& face); /// checks the local voxel tree for the smallest voxel enclosing the point /// \param point the x,y,z coordinates of the point (in meter units) /// \return VoxelDetail - if no voxel encloses the point then VoxelDetail items will be 0 - VoxelDetail getVoxelEnclosingPoint(const glm::vec3& point); + Q_INVOKABLE VoxelDetail getVoxelEnclosingPoint(const glm::vec3& point); private: + /// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode + RayToVoxelIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType); + void queueVoxelAdd(PacketType addPacketType, VoxelDetail& addVoxelDetails); VoxelTree* _tree; QUndoStack* _undoStack; From 7787cf97b6cc351771b10a5a73b190f0e3d0f8d4 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 29 Apr 2014 16:30:14 -0700 Subject: [PATCH 29/37] Only glow body + fixed display name scale --- interface/src/avatar/Avatar.cpp | 32 ++++++++++++++++++-------------- interface/src/avatar/Avatar.h | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index b060c3421a..71bd05a7c6 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -206,13 +206,13 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode) { GLOW_FROM_AVERAGE_LOUDNESS = 0.0f; } - Glower glower(_moving && distanceToTarget > GLOW_DISTANCE && renderMode == NORMAL_RENDER_MODE + float glowLevel = _moving && distanceToTarget > GLOW_DISTANCE && renderMode == NORMAL_RENDER_MODE ? 1.0f - : GLOW_FROM_AVERAGE_LOUDNESS); + : GLOW_FROM_AVERAGE_LOUDNESS; // render body if (Menu::getInstance()->isOptionChecked(MenuOption::Avatars)) { - renderBody(renderMode); + renderBody(renderMode, glowLevel); } if (Menu::getInstance()->isOptionChecked(MenuOption::RenderSkeletonCollisionShapes)) { _skeletonModel.updateShapePositions(); @@ -326,17 +326,21 @@ glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const { return glm::angleAxis(angle * proportion, axis); } -void Avatar::renderBody(RenderMode renderMode) { - if (_shouldRenderBillboard || !(_skeletonModel.isRenderable() && getHead()->getFaceModel().isRenderable())) { - // render the billboard until both models are loaded - renderBillboard(); - return; - } +void Avatar::renderBody(RenderMode renderMode, float glowLevel) { Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ? - Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; - _skeletonModel.render(1.0f, modelRenderMode); + Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; + { + Glower glower(glowLevel); + + if (_shouldRenderBillboard || !(_skeletonModel.isRenderable() && getHead()->getFaceModel().isRenderable())) { + // render the billboard until both models are loaded + renderBillboard(); + return; + } + _skeletonModel.render(1.0f, modelRenderMode); + getHand()->render(false); + } getHead()->render(1.0f, modelRenderMode); - getHand()->render(false); } bool Avatar::shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const { @@ -451,7 +455,7 @@ void Avatar::renderDisplayName() { // The up vector must be relative to the rotation current rotation matrix: // we set the identity glm::dvec3 testPoint0 = glm::dvec3(textPosition); - glm::dvec3 testPoint1 = glm::dvec3(textPosition) + glm::dvec3(IDENTITY_UP); + glm::dvec3 testPoint1 = glm::dvec3(textPosition) + glm::dvec3(Application::getInstance()->getCamera()->getRotation() * IDENTITY_UP); bool success; success = gluProject(testPoint0.x, testPoint0.y, testPoint0.z, @@ -466,7 +470,7 @@ void Avatar::renderDisplayName() { double textWindowHeight = abs(result1[1] - result0[1]); float scaleFactor = (textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f; glScalef(scaleFactor, scaleFactor, 1.0); - + glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis int text_x = -_displayNameBoundingRect.width() / 2; diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index bcf3487e09..df1340b79a 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -185,7 +185,7 @@ protected: float getPelvisToHeadLength() const; void renderDisplayName(); - virtual void renderBody(RenderMode renderMode); + virtual void renderBody(RenderMode renderMode, float glowLevel); virtual bool shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const; virtual void updateJointMappings(); From e0ec0f681fb95fd0459fb286027bccd3da45b47f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 29 Apr 2014 16:50:13 -0700 Subject: [PATCH 30/37] Fix code not compliant with coding standards --- interface/src/Application.cpp | 6 +-- interface/src/MainWindow.cpp | 52 +++++++++++------------ interface/src/MainWindow.h | 16 ++++--- interface/src/ui/FramelessDialog.h | 8 ++-- interface/src/ui/RunningScriptsWidget.cpp | 41 +++++++----------- interface/src/ui/RunningScriptsWidget.h | 12 +++--- interface/src/ui/ScriptsTableWidget.cpp | 26 ++++++------ interface/src/ui/ScriptsTableWidget.h | 19 +++++---- 8 files changed, 88 insertions(+), 92 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9f8bdc2e5f..0d5e8a8b03 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3335,8 +3335,7 @@ void Application::reloadAllScripts() { } } -void Application::manageRunningScriptsWidgetVisibility(bool shown) -{ +void Application::manageRunningScriptsWidgetVisibility(bool shown) { if (_runningScriptsWidgetWasVisible && shown) { _runningScriptsWidget->show(); } else if (_runningScriptsWidgetWasVisible && !shown) { @@ -3344,8 +3343,7 @@ void Application::manageRunningScriptsWidgetVisibility(bool shown) } } -void Application::toggleRunningScriptsWidget() -{ +void Application::toggleRunningScriptsWidget() { qDebug() << "RS"; if (_runningScriptsWidgetWasVisible) { _runningScriptsWidget->hide(); diff --git a/interface/src/MainWindow.cpp b/interface/src/MainWindow.cpp index 4711d97232..7fddbfffa3 100644 --- a/interface/src/MainWindow.cpp +++ b/interface/src/MainWindow.cpp @@ -4,6 +4,10 @@ // // Created by Mohammed Nafees on 04/06/2014. // Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// #include "MainWindow.h" @@ -14,56 +18,50 @@ #include #include -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent) -{ +MainWindow::MainWindow(QWidget* parent) : + QMainWindow(parent) { } -void MainWindow::moveEvent(QMoveEvent *e) -{ - emit windowGeometryChanged(QRect(e->pos(), size())); - QMainWindow::moveEvent(e); +void MainWindow::moveEvent(QMoveEvent* event) { + emit windowGeometryChanged(QRect(event->pos(), size())); + QMainWindow::moveEvent(event); } -void MainWindow::resizeEvent(QResizeEvent *e) -{ - emit windowGeometryChanged(QRect(QPoint(x(), y()), e->size())); - QMainWindow::resizeEvent(e); +void MainWindow::resizeEvent(QResizeEvent* event) { + emit windowGeometryChanged(QRect(QPoint(x(), y()), event->size())); + QMainWindow::resizeEvent(event); } -void MainWindow::showEvent(QShowEvent *e) -{ - if (e->spontaneous()) { +void MainWindow::showEvent(QShowEvent* event) { + if (event->spontaneous()) { emit windowShown(true); } - QMainWindow::showEvent(e); + QMainWindow::showEvent(event); } -void MainWindow::hideEvent(QHideEvent *e) -{ - if (e->spontaneous()) { +void MainWindow::hideEvent(QHideEvent* event) { + if (event->spontaneous()) { emit windowShown(false); } - QMainWindow::hideEvent(e); + QMainWindow::hideEvent(event); } -void MainWindow::changeEvent(QEvent *e) -{ - if (e->type() == QEvent::WindowStateChange) { - QWindowStateChangeEvent *event = static_cast(e); - if ((event->oldState() == Qt::WindowNoState || - event->oldState() == Qt::WindowMaximized) && +void MainWindow::changeEvent(QEvent* event) { + if (event->type() == QEvent::WindowStateChange) { + QWindowStateChangeEvent* stateChangeEvent = static_cast(event); + if ((stateChangeEvent->oldState() == Qt::WindowNoState || + stateChangeEvent->oldState() == Qt::WindowMaximized) && windowState() == Qt::WindowMinimized) { emit windowShown(false); } else { emit windowShown(true); } - } else if (e->type() == QEvent::ActivationChange) { + } else if (event->type() == QEvent::ActivationChange) { if (isActiveWindow()) { emit windowShown(true); } else { emit windowShown(false); } } - QMainWindow::changeEvent(e); + QMainWindow::changeEvent(event); } diff --git a/interface/src/MainWindow.h b/interface/src/MainWindow.h index 5c4168923b..603194e9be 100644 --- a/interface/src/MainWindow.h +++ b/interface/src/MainWindow.h @@ -4,6 +4,10 @@ // // Created by Mohammed Nafees on 04/06/2014. // Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// #ifndef __hifi__MainWindow__ #define __hifi__MainWindow__ @@ -14,18 +18,18 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget* parent = NULL); signals: void windowGeometryChanged(QRect geometry); void windowShown(bool shown); protected: - virtual void moveEvent(QMoveEvent *e); - virtual void resizeEvent(QResizeEvent *e); - virtual void showEvent(QShowEvent *e); - virtual void hideEvent(QHideEvent *e); - virtual void changeEvent(QEvent *e); + virtual void moveEvent(QMoveEvent* event); + virtual void resizeEvent(QResizeEvent* event); + virtual void showEvent(QShowEvent* event); + virtual void hideEvent(QHideEvent* event); + virtual void changeEvent(QEvent* event); }; #endif /* defined(__hifi__MainWindow__) */ diff --git a/interface/src/ui/FramelessDialog.h b/interface/src/ui/FramelessDialog.h index e8d6cd5393..9a958507aa 100644 --- a/interface/src/ui/FramelessDialog.h +++ b/interface/src/ui/FramelessDialog.h @@ -23,10 +23,10 @@ public: FramelessDialog(QWidget* parent, Qt::WindowFlags flags = 0, Position position = POSITION_LEFT); void setStyleSheetFile(const QString& fileName); - void setAllowResize(bool allowResize) { _allowResize = allowResize; }; - bool getAllowResize() { return _allowResize; }; - void setHideOnBlur(bool hideOnBlur) { _hideOnBlur = hideOnBlur; }; - bool getHideOnBlur() { return _hideOnBlur; }; + void setAllowResize(bool allowResize) { _allowResize = allowResize; } + bool getAllowResize() { return _allowResize; } + void setHideOnBlur(bool hideOnBlur) { _hideOnBlur = hideOnBlur; } + bool getHideOnBlur() { return _hideOnBlur; } void resizeAndPosition(bool resizeParent = true); protected: diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index b27d99aaae..686fce7510 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -12,17 +12,16 @@ #include "ui_runningScriptsWidget.h" #include "RunningScriptsWidget.h" -#include #include +#include #include #include #include "Application.h" -RunningScriptsWidget::RunningScriptsWidget(QWidget *parent) : +RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : FramelessDialog(parent, 0, POSITION_LEFT), - ui(new Ui::RunningScriptsWidget) -{ + ui(new Ui::RunningScriptsWidget) { ui->setupUi(this); setAllowResize(false); @@ -54,18 +53,15 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget *parent) : Application::getInstance(), &Application::loadDialog); } -RunningScriptsWidget::~RunningScriptsWidget() -{ +RunningScriptsWidget::~RunningScriptsWidget() { delete ui; } -void RunningScriptsWidget::setBoundary(const QRect &rect) -{ +void RunningScriptsWidget::setBoundary(const QRect& rect) { _boundary = rect; } -void RunningScriptsWidget::setRunningScripts(const QStringList& list) -{ +void RunningScriptsWidget::setRunningScripts(const QStringList& list) { _runningScriptsTable->setRowCount(list.size()); ui->noRunningScriptsLabel->setVisible(list.isEmpty()); @@ -104,10 +100,10 @@ void RunningScriptsWidget::setRunningScripts(const QStringList& list) createRecentlyLoadedScriptsTable(); } -void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) +void RunningScriptsWidget::keyPressEvent(QKeyEvent* event) { int loadScriptNumber = -1; - switch(e->key()) { + switch(event->key()) { case Qt::Key_Escape: Application::getInstance()->toggleRunningScriptsWidget(); break; @@ -156,11 +152,10 @@ void RunningScriptsWidget::keyPressEvent(QKeyEvent *e) } } - FramelessDialog::keyPressEvent(e); + FramelessDialog::keyPressEvent(event); } -void RunningScriptsWidget::paintEvent(QPaintEvent *) -{ +void RunningScriptsWidget::paintEvent(QPaintEvent* event) { QPainter painter(this); painter.setPen(QColor::fromRgb(225, 225, 225)); // #e1e1e1 @@ -179,21 +174,18 @@ void RunningScriptsWidget::paintEvent(QPaintEvent *) painter.end(); } -void RunningScriptsWidget::stopScript(int row, int column) -{ +void RunningScriptsWidget::stopScript(int row, int column) { if (column == 1) { // make sure the user has clicked on the close icon _lastStoppedScript = _runningScriptsTable->item(row, 0)->toolTip(); emit stopScriptName(_runningScriptsTable->item(row, 0)->toolTip()); } } -void RunningScriptsWidget::loadScript(int row, int column) -{ +void RunningScriptsWidget::loadScript(int row, int column) { Application::getInstance()->loadScript(_recentlyLoadedScriptsTable->item(row, column)->toolTip()); } -void RunningScriptsWidget::allScriptsStopped() -{ +void RunningScriptsWidget::allScriptsStopped() { QStringList list = Application::getInstance()->getRunningScripts(); for (int i = 0; i < list.size(); ++i) { _recentlyLoadedScripts.prepend(list.at(i)); @@ -202,8 +194,7 @@ void RunningScriptsWidget::allScriptsStopped() Application::getInstance()->stopAllScripts(); } -void RunningScriptsWidget::createRecentlyLoadedScriptsTable() -{ +void RunningScriptsWidget::createRecentlyLoadedScriptsTable() { if (!_recentlyLoadedScripts.contains(_lastStoppedScript) && !_lastStoppedScript.isEmpty()) { _recentlyLoadedScripts.prepend(_lastStoppedScript); _lastStoppedScript = ""; @@ -221,9 +212,9 @@ void RunningScriptsWidget::createRecentlyLoadedScriptsTable() int limit = _recentlyLoadedScripts.size() > 9 ? 9 : _recentlyLoadedScripts.size(); _recentlyLoadedScriptsTable->setRowCount(limit); - for (int i = 0; i < limit; ++i) { + for (int i = 0; i < limit; i++) { QTableWidgetItem *scriptName = new QTableWidgetItem; - scriptName->setText(QString::number(i+1) + ". " +QFileInfo(_recentlyLoadedScripts.at(i)).fileName()); + scriptName->setText(QString::number(i + 1) + ". " + QFileInfo(_recentlyLoadedScripts.at(i)).fileName()); scriptName->setToolTip(_recentlyLoadedScripts.at(i)); scriptName->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); diff --git a/interface/src/ui/RunningScriptsWidget.h b/interface/src/ui/RunningScriptsWidget.h index 8f82df9a5e..ad310c4ed4 100644 --- a/interface/src/ui/RunningScriptsWidget.h +++ b/interface/src/ui/RunningScriptsWidget.h @@ -23,7 +23,7 @@ class RunningScriptsWidget : public FramelessDialog { Q_OBJECT public: - explicit RunningScriptsWidget(QWidget *parent = 0); + explicit RunningScriptsWidget(QWidget* parent = NULL); ~RunningScriptsWidget(); void setRunningScripts(const QStringList& list); @@ -32,8 +32,8 @@ signals: void stopScriptName(const QString& name); protected: - virtual void keyPressEvent(QKeyEvent *e); - virtual void paintEvent(QPaintEvent *); + virtual void keyPressEvent(QKeyEvent* event); + virtual void paintEvent(QPaintEvent* event); public slots: void setBoundary(const QRect& rect); @@ -44,9 +44,9 @@ private slots: void allScriptsStopped(); private: - Ui::RunningScriptsWidget *ui; - ScriptsTableWidget *_runningScriptsTable; - ScriptsTableWidget *_recentlyLoadedScriptsTable; + Ui::RunningScriptsWidget* ui; + ScriptsTableWidget* _runningScriptsTable; + ScriptsTableWidget* _recentlyLoadedScriptsTable; QStringList _recentlyLoadedScripts; QString _lastStoppedScript; QRect _boundary; diff --git a/interface/src/ui/ScriptsTableWidget.cpp b/interface/src/ui/ScriptsTableWidget.cpp index 12150ae625..95acca052c 100644 --- a/interface/src/ui/ScriptsTableWidget.cpp +++ b/interface/src/ui/ScriptsTableWidget.cpp @@ -4,17 +4,20 @@ // // Created by Mohammed Nafees on 04/03/2014. // Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include +#include #include "ScriptsTableWidget.h" -#include -#include -#include -#include - -ScriptsTableWidget::ScriptsTableWidget(QWidget *parent) : - QTableWidget(parent) -{ +ScriptsTableWidget::ScriptsTableWidget(QWidget* parent) : + QTableWidget(parent) { verticalHeader()->setVisible(false); horizontalHeader()->setVisible(false); setShowGrid(false); @@ -26,13 +29,12 @@ ScriptsTableWidget::ScriptsTableWidget(QWidget *parent) : setGeometry(0, 0, parent->width(), parent->height()); } -void ScriptsTableWidget::paintEvent(QPaintEvent *event) -{ +void ScriptsTableWidget::paintEvent(QPaintEvent* event) { QPainter painter(viewport()); painter.setPen(QColor::fromRgb(225, 225, 225)); // #e1e1e1 int y = 0; - for (int i = 0; i < rowCount(); ++i) { + for (int i = 0; i < rowCount(); i++) { painter.drawLine(5, rowHeight(i) + y, width(), rowHeight(i) + y); y += rowHeight(i); } @@ -41,7 +43,7 @@ void ScriptsTableWidget::paintEvent(QPaintEvent *event) QTableWidget::paintEvent(event); } -void ScriptsTableWidget::keyPressEvent(QKeyEvent *event) { +void ScriptsTableWidget::keyPressEvent(QKeyEvent* event) { // Ignore keys so they will propagate correctly event->ignore(); } diff --git a/interface/src/ui/ScriptsTableWidget.h b/interface/src/ui/ScriptsTableWidget.h index ee9f87928a..4b54130e82 100644 --- a/interface/src/ui/ScriptsTableWidget.h +++ b/interface/src/ui/ScriptsTableWidget.h @@ -4,22 +4,25 @@ // // Created by Mohammed Nafees on 04/03/2014. // Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// -#ifndef __hifi__ScriptsTableWidget__ -#define __hifi__ScriptsTableWidget__ +#ifndef hifi__ScriptsTableWidget_h +#define hifi__ScriptsTableWidget_h #include #include -class ScriptsTableWidget : public QTableWidget -{ +class ScriptsTableWidget : public QTableWidget { Q_OBJECT public: - explicit ScriptsTableWidget(QWidget *parent); + explicit ScriptsTableWidget(QWidget* parent); protected: - virtual void paintEvent(QPaintEvent *event); - virtual void keyPressEvent(QKeyEvent *event); + virtual void paintEvent(QPaintEvent* event); + virtual void keyPressEvent(QKeyEvent* event); }; -#endif /* defined(__hifi__ScriptsTableWidget__) */ +#endif // hifi__ScriptsTableWidget_h From 39c959d2455b6b4f1eba05ffbabf31280ac00b5d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 29 Apr 2014 17:03:38 -0700 Subject: [PATCH 31/37] Clean up implementation of 1-9 in RunningScripts --- interface/src/ui/RunningScriptsWidget.cpp | 31 +++-------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 686fce7510..e3c38b855a 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -109,46 +109,23 @@ void RunningScriptsWidget::keyPressEvent(QKeyEvent* event) break; case Qt::Key_1: - loadScriptNumber = 1; - break; - case Qt::Key_2: - loadScriptNumber = 2; - break; - case Qt::Key_3: - loadScriptNumber = 3; - break; - case Qt::Key_4: - loadScriptNumber = 4; - break; - case Qt::Key_5: - loadScriptNumber = 5; - break; - case Qt::Key_6: - loadScriptNumber = 6; - break; - case Qt::Key_7: - loadScriptNumber = 7; - break; case Qt::Key_8: - loadScriptNumber = 8; - break; - case Qt::Key_9: - loadScriptNumber = 9; + loadScriptNumber = event->key() - Qt::Key_1; break; default: break; } - if (loadScriptNumber > 0) { - if (_recentlyLoadedScripts.size() >= loadScriptNumber) { - Application::getInstance()->loadScript(_recentlyLoadedScripts.at(loadScriptNumber - 1)); + if (loadScriptNumber >= 0) { + if (_recentlyLoadedScripts.size() > loadScriptNumber) { + Application::getInstance()->loadScript(_recentlyLoadedScripts.at(loadScriptNumber)); } } From 98a736a39c152bd5c94def1d8b1c4106eb8d2685 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 29 Apr 2014 17:04:02 -0700 Subject: [PATCH 32/37] Remove duplicate method declaration --- interface/src/ui/FramelessDialog.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/ui/FramelessDialog.h b/interface/src/ui/FramelessDialog.h index 9a958507aa..32451f746d 100644 --- a/interface/src/ui/FramelessDialog.h +++ b/interface/src/ui/FramelessDialog.h @@ -38,8 +38,6 @@ protected: bool eventFilter(QObject* sender, QEvent* event); private: - void resizeAndPosition(bool resizeParent = true); - bool _allowResize; bool _isResizing; int _resizeInitialWidth; From 2ba0c8c237cb1e9575a2ca8224d2637caeb5d6bf Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 29 Apr 2014 17:10:09 -0700 Subject: [PATCH 33/37] Remove magic numbers from RunningScriptsWidget --- interface/src/ui/RunningScriptsWidget.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index e3c38b855a..95523683c4 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -82,19 +82,23 @@ void RunningScriptsWidget::setRunningScripts(const QStringList& list) { _runningScriptsTable->setItem(i, 1, closeIcon); } - int y = ui->runningScriptsTableWidget->y() + 12; + const int RUNNING_SCRIPTS_TABLE_LEFT_MARGIN = 12; + const int RECENTLY_LOADED_TOP_MARGIN = 61; + const int RECENTLY_LOADED_LABEL_TOP_MARGIN = 19; + + int y = ui->runningScriptsTableWidget->y() + RUNNING_SCRIPTS_TABLE_LEFT_MARGIN; for (int i = 0; i < _runningScriptsTable->rowCount(); ++i) { y += _runningScriptsTable->rowHeight(i); } - ui->runningScriptsTableWidget->resize(ui->runningScriptsTableWidget->width(), y - 12); - _runningScriptsTable->resize(_runningScriptsTable->width(), y - 12); + ui->runningScriptsTableWidget->resize(ui->runningScriptsTableWidget->width(), y - RUNNING_SCRIPTS_TABLE_LEFT_MARGIN); + _runningScriptsTable->resize(_runningScriptsTable->width(), y - RUNNING_SCRIPTS_TABLE_LEFT_MARGIN); ui->reloadAllButton->move(ui->reloadAllButton->x(), y); ui->stopAllButton->move(ui->stopAllButton->x(), y); ui->recentlyLoadedLabel->move(ui->recentlyLoadedLabel->x(), - ui->stopAllButton->y() + ui->stopAllButton->height() + 61); + ui->stopAllButton->y() + ui->stopAllButton->height() + RECENTLY_LOADED_TOP_MARGIN); ui->recentlyLoadedScriptsTableWidget->move(ui->recentlyLoadedScriptsTableWidget->x(), - ui->recentlyLoadedLabel->y() + 19); + ui->recentlyLoadedLabel->y() + RECENTLY_LOADED_LABEL_TOP_MARGIN); createRecentlyLoadedScriptsTable(); From fa9e37daad794a8f79604d3b14d7bbff4812e788 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 29 Apr 2014 17:16:12 -0700 Subject: [PATCH 34/37] Remove unneeded qDebug() --- interface/src/Application.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0d5e8a8b03..f93b2b7f68 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3344,7 +3344,6 @@ void Application::manageRunningScriptsWidgetVisibility(bool shown) { } void Application::toggleRunningScriptsWidget() { - qDebug() << "RS"; if (_runningScriptsWidgetWasVisible) { _runningScriptsWidget->hide(); _runningScriptsWidgetWasVisible = false; From 8ee90715bd34cb1a065178cc6292ff42e19b5f71 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 29 Apr 2014 17:20:15 -0700 Subject: [PATCH 35/37] Revert changes to call to saveSettings in Application --- interface/src/Application.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f93b2b7f68..a2c10c02cd 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -370,15 +370,11 @@ Application::~Application() { // make sure we don't call the idle timer any more delete idleTimer; - Menu::getInstance()->saveSettings(); - _rearMirrorTools->saveSettings(_settings); - _sharedVoxelSystem.changeTree(new VoxelTree); - if (_voxelImporter) { - _voxelImporter->saveSettings(_settings); - delete _voxelImporter; - } - _settings->sync(); + + saveSettings(); + + delete _voxelImporter; // let the avatar mixer know we're out MyAvatar::sendKillAvatar(); From 1551da9e996ff61f3bc9822fd63f42b38d4fabd4 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 29 Apr 2014 17:23:30 -0700 Subject: [PATCH 36/37] Remove magic number in RunningScripts --- interface/src/ui/RunningScriptsWidget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 95523683c4..61241f71fb 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -70,13 +70,15 @@ void RunningScriptsWidget::setRunningScripts(const QStringList& list) { ui->reloadAllButton->setVisible(!list.isEmpty()); ui->stopAllButton->setVisible(!list.isEmpty()); + const int CLOSE_ICON_HEIGHT = 12; + for (int i = 0; i < list.size(); ++i) { QTableWidgetItem *scriptName = new QTableWidgetItem; scriptName->setText(QFileInfo(list.at(i)).fileName()); scriptName->setToolTip(list.at(i)); scriptName->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); QTableWidgetItem *closeIcon = new QTableWidgetItem; - closeIcon->setIcon(QIcon(QPixmap(Application::resourcesPath() + "images/kill-script.svg").scaledToHeight(12))); + closeIcon->setIcon(QIcon(QPixmap(Application::resourcesPath() + "images/kill-script.svg").scaledToHeight(CLOSE_ICON_HEIGHT))); _runningScriptsTable->setItem(i, 0, scriptName); _runningScriptsTable->setItem(i, 1, closeIcon); From e9a01a39a29e77840c65520cd0cf61a5dceec281 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 29 Apr 2014 17:38:55 -0700 Subject: [PATCH 37/37] Fixed QLINE_MIN_WIDTH warning on mac --- interface/src/Menu.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 59da23dc88..70c69e2b94 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -814,7 +814,6 @@ void sendFakeEnterEvent() { QCoreApplication::sendEvent(glWidget, &enterEvent); } -const int QLINE_MINIMUM_WIDTH = 400; const float DIALOG_RATIO_OF_WINDOW = 0.30f; void Menu::loginForCurrentDomain() {