This commit is contained in:
Stojce Slavkovski 2013-12-18 20:37:45 +01:00
parent a2ad70524f
commit 45d926da41
8 changed files with 59 additions and 65 deletions

View file

@ -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();
}
}

View file

@ -18,6 +18,7 @@
#include <QSettings>
#include <QTouchEvent>
#include <QList>
#include <QPointer>
#include <NetworkPacket.h>
#include <NodeList.h>
@ -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<VoxelFade> _voxelFades;
std::vector<Avatar*> _avatarFades;
QPointer<LogDialog> _logDialog;
};
#endif /* defined(__interface__Application__) */

View file

@ -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
//

View file

@ -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);

View file

@ -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(),

View file

@ -13,7 +13,6 @@
#include <QHash>
#include <QKeySequence>
#include "ui/LogDialog.h"
#include <AbstractMenuInterface.h>
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;
};

View file

@ -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>("QTextCursor");
int blockMeta = qRegisterMetaType<QTextBlock>("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<int>(screen.height() * INITIAL_HEIGHT_RATIO));
move(screen.center() - rect().center());
delete desktop;
QDesktopWidget desktop;
QRect screen = desktop.screenGeometry();
resize(INITIAL_WIDTH, static_cast<int>(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();
}

View file

@ -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);