From 45d926da41be3ff91322f0b98f2183475d34f75f Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Wed, 18 Dec 2013 20:37:45 +0100 Subject: [PATCH] CR fixes --- interface/src/Application.cpp | 9 ++++++ interface/src/Application.h | 6 +++- interface/src/LogDisplay.cpp | 14 +++++++- interface/src/LogDisplay.h | 3 +- interface/src/Menu.cpp | 22 ++----------- interface/src/Menu.h | 4 --- interface/src/ui/LogDialog.cpp | 58 +++++++++++++++------------------- interface/src/ui/LogDialog.h | 8 ++--- 8 files changed, 59 insertions(+), 65 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3d6078d541..efe2193629 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4478,3 +4478,12 @@ void Application::loadScript() { // restore the main window's active state _window->activateWindow(); } + +void Application::toggleLogDialog() { + if (! _logDialog) { + _logDialog = new LogDialog(_glWidget); + _logDialog->show(); + } else { + _logDialog->close(); + } +} diff --git a/interface/src/Application.h b/interface/src/Application.h index 5f8aaffd23..7680388e9f 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -67,6 +68,7 @@ #include "ui/VoxelStatsDialog.h" #include "ui/RearMirrorTools.h" #include "ui/LodToolsDialog.h" +#include "ui/LogDialog.h" #include "ParticleTreeRenderer.h" #include "ParticleEditHandle.h" @@ -222,7 +224,7 @@ public slots: void decreaseVoxelSize(); void increaseVoxelSize(); void loadScript(); - + void toggleLogDialog(); private slots: @@ -503,6 +505,8 @@ private: std::vector _voxelFades; std::vector _avatarFades; + + QPointer _logDialog; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/LogDisplay.cpp b/interface/src/LogDisplay.cpp index dcfbbff626..84a1abd364 100644 --- a/interface/src/LogDisplay.cpp +++ b/interface/src/LogDisplay.cpp @@ -90,8 +90,8 @@ void LogDisplay::setCharacterSize(unsigned width, unsigned height) { void LogDisplay::addMessage(const char* ptr) { - emit logReceived(ptr); pthread_mutex_lock(& _mutex); + emit logReceived(ptr); // T-pipe, if requested if (_stream != 0l) { @@ -155,6 +155,18 @@ void LogDisplay::addMessage(const char* ptr) { pthread_mutex_unlock(& _mutex); } +QStringList LogDisplay::getLogData() { + // wait for adding new log data whilr iterating over _lines + pthread_mutex_lock(& _mutex); + QStringList list; + int i = 0; + while (_lines[i] != *_lastLinePos) { + list.append(_lines[i++]); + } + pthread_mutex_unlock(& _mutex); + return list; +} + // // Rendering // diff --git a/interface/src/LogDisplay.h b/interface/src/LogDisplay.h index 29080d075e..285325b180 100644 --- a/interface/src/LogDisplay.h +++ b/interface/src/LogDisplay.h @@ -44,8 +44,7 @@ public: static unsigned const LINE_BUFFER_SIZE = 256; // number of lines that are buffered static unsigned const MAX_MESSAGE_LENGTH = 512; // maximum number of characters for a message - char** getLogData() { return _lines; }; - char** getLastLinePos() { return _lastLinePos; } + QStringList getLogData(); signals: void logReceived(QString message); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 0cfe7928b4..38f4ae3bae 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -69,8 +69,7 @@ Menu::Menu() : _maxVoxels(DEFAULT_MAX_VOXELS_PER_SYSTEM), _voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE), _boundaryLevelAdjust(0), - _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS), - _logDialog(NULL) + _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS) { Application *appInstance = Application::getInstance(); @@ -266,7 +265,7 @@ Menu::Menu() : addDisabledActionAndSeparator(viewMenu, "Stats"); addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Stats, Qt::Key_Slash); - addActionToQMenuAndActionHash(viewMenu, MenuOption::Log, Qt::CTRL | Qt::Key_L, this, SLOT(showLogDialog())); + addActionToQMenuAndActionHash(viewMenu, MenuOption::Log, Qt::CTRL | Qt::Key_L, appInstance, SLOT(toggleLogDialog())); addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Oscilloscope, 0, true); addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Bandwidth, 0, true); addActionToQMenuAndActionHash(viewMenu, MenuOption::BandwidthDetails, 0, this, SLOT(bandwidthDetails())); @@ -1029,23 +1028,6 @@ void Menu::pasteToVoxel() { sendFakeEnterEvent(); } -void Menu::showLogDialog() { - if (! _logDialog) { - _logDialog = new LogDialog(Application::getInstance()->getGLWidget()); - connect(_logDialog, SIGNAL(closed()), SLOT(logDialogClosed())); - _logDialog->show(); - } else { - _logDialog->close(); - } -} - -void Menu::logDialogClosed() { - if (_logDialog) { - delete _logDialog; - _logDialog = NULL; - } -} - void Menu::bandwidthDetails() { if (! _bandwidthDialog) { _bandwidthDialog = new BandwidthDialog(Application::getInstance()->getGLWidget(), diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 8b31d50578..c5742cc570 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -13,7 +13,6 @@ #include #include -#include "ui/LogDialog.h" #include enum FrustumDrawMode { @@ -93,7 +92,6 @@ public slots: void exportSettings(); void goToUser(); void pasteToVoxel(); - void showLogDialog(); private slots: void aboutApp(); @@ -109,7 +107,6 @@ private slots: void chooseVoxelPaintColor(); void runTests(); void resetSwatchColors(); - void logDialogClosed(); private: static Menu* _instance; @@ -149,7 +146,6 @@ private: int _boundaryLevelAdjust; QAction* _useVoxelShader; int _maxVoxelPacketsPerSecond; - LogDialog* _logDialog; QMenu* _activeScriptsMenu; }; diff --git a/interface/src/ui/LogDialog.cpp b/interface/src/ui/LogDialog.cpp index 1ada9df2ca..013c60d993 100644 --- a/interface/src/ui/LogDialog.cpp +++ b/interface/src/ui/LogDialog.cpp @@ -14,52 +14,50 @@ #include "ui/LogDialog.h" #include "LogDisplay.h" -#define INITIAL_WIDTH_RATIO 0.7 -#define INITIAL_HEIGHT_RATIO 0.6 +const int INITIAL_WIDTH = 720; +const float INITIAL_HEIGHT_RATIO = 0.6f; int cursorMeta = qRegisterMetaType("QTextCursor"); int blockMeta = qRegisterMetaType("QTextBlock"); LogDialog::LogDialog(QWidget* parent) : QDialog(parent, Qt::Dialog) { - setWindowTitle("Log"); + setWindowTitle("Log"); - _logTextBox = new QPlainTextEdit(this); - _logTextBox->setReadOnly(true); - _logTextBox->show(); + _logTextBox = new QPlainTextEdit(this); + _logTextBox->setReadOnly(true); + _logTextBox->show(); - switchToResourcesParentIfRequired(); - QFile styleSheet("resources/styles/log_dialog.qss"); + switchToResourcesParentIfRequired(); + QFile styleSheet("resources/styles/log_dialog.qss"); - if (styleSheet.open(QIODevice::ReadOnly)) { - setStyleSheet(styleSheet.readAll()); - } + if (styleSheet.open(QIODevice::ReadOnly)) { + setStyleSheet(styleSheet.readAll()); + } - QDesktopWidget* desktop = new QDesktopWidget(); - QRect screen = desktop->screenGeometry(); - resize(720, static_cast(screen.height() * INITIAL_HEIGHT_RATIO)); - move(screen.center() - rect().center()); - delete desktop; + QDesktopWidget desktop; + QRect screen = desktop.screenGeometry(); + resize(INITIAL_WIDTH, static_cast(screen.height() * INITIAL_HEIGHT_RATIO)); + move(screen.center() - rect().center()); + + setAttribute(Qt::WA_DeleteOnClose); } LogDialog::~LogDialog() { deleteLater(); - delete _logTextBox; } void LogDialog::showEvent(QShowEvent *e) { _logTextBox->clear(); - pthread_mutex_lock(& _mutex); - char** _lines = LogDisplay::instance.getLogData(); - char** _lastLinePos = LogDisplay::instance.getLastLinePos(); - int i = 0; - while (_lines[i] != *_lastLinePos) { - appendLogLine(_lines[i]); - i++; - } + pthread_mutex_lock(& _mutex); + QStringList _logData = LogDisplay::instance.getLogData(); connect(&LogDisplay::instance, &LogDisplay::logReceived, this, &LogDialog::appendLogLine); + for(int i = 0; i < _logData.size(); ++i) { + appendLogLine(_logData[i]); + } + pthread_mutex_unlock(& _mutex); } @@ -69,15 +67,9 @@ void LogDialog::resizeEvent(QResizeEvent *e) { void LogDialog::appendLogLine(QString logLine) { if (isVisible()) { + pthread_mutex_lock(& _mutex); _logTextBox->appendPlainText(logLine.simplified()); + pthread_mutex_unlock(& _mutex); _logTextBox->ensureCursorVisible(); } } - -void LogDialog::reject() { - close(); -} - -void LogDialog::closeEvent(QCloseEvent* event) { - emit closed(); -} diff --git a/interface/src/ui/LogDialog.h b/interface/src/ui/LogDialog.h index 7b445b6f4f..8146bc29e6 100644 --- a/interface/src/ui/LogDialog.h +++ b/interface/src/ui/LogDialog.h @@ -19,16 +19,16 @@ public: LogDialog(QWidget* parent); ~LogDialog(); -signals: - void closed(); +//signals: +// void closed(); public slots: - void reject(); +// void reject(); void appendLogLine(QString logLine); protected: // Emits a 'closed' signal when this dialog is closed. - void closeEvent(QCloseEvent* e); +// void closeEvent(QCloseEvent* e); void resizeEvent(QResizeEvent* e); void showEvent(QShowEvent* e);