From 3d44ab9939ffe6400806fcf89c5892204f6c8ab8 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sun, 22 Dec 2013 15:06:40 +0100 Subject: [PATCH] Dialog layout --- interface/resources/styles/checked.svg | 14 +++ interface/resources/styles/log_dialog.qss | 46 ++++++++++ interface/resources/styles/search.svg | 12 +++ interface/resources/styles/txt-file.svg | 15 +++ interface/resources/styles/unchecked.svg | 11 +++ interface/src/LogDisplay.cpp | 7 +- interface/src/LogDisplay.h | 2 +- interface/src/ui/LogDialog.cpp | 107 +++++++++++++++++++--- interface/src/ui/LogDialog.h | 18 +++- 9 files changed, 213 insertions(+), 19 deletions(-) create mode 100644 interface/resources/styles/checked.svg create mode 100644 interface/resources/styles/search.svg create mode 100644 interface/resources/styles/txt-file.svg create mode 100644 interface/resources/styles/unchecked.svg diff --git a/interface/resources/styles/checked.svg b/interface/resources/styles/checked.svg new file mode 100644 index 0000000000..03cee0794e --- /dev/null +++ b/interface/resources/styles/checked.svg @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/interface/resources/styles/log_dialog.qss b/interface/resources/styles/log_dialog.qss index fe3675f682..ab74f07a33 100644 --- a/interface/resources/styles/log_dialog.qss +++ b/interface/resources/styles/log_dialog.qss @@ -1,7 +1,53 @@ + QPlainTextEdit { font-family: Inconsolata, Lucida Console, Andale Mono, Monaco; font-size: 16px; padding-left: 28px; + padding-top: 7px; color: #333333; background-color: #FFFFFF; + border: none; +} + +QLineEdit { + padding-left: 7px; + background-color: #CCCCCC; + border-width: 0; + border-top-right-radius: 9px; + border-bottom-right-radius: 9px; + color: #333333; + font-size: 12px; +} + +QPushButton#searchButton { + background: url(resources/styles/search.svg); + background-repeat: none; + background-position: left center; + background-origin: content; + padding-left: 7px; + background-color: #CCCCCC; + border-width: 0; + border-top-left-radius: 9px; + border-bottom-left-radius: 9px; +} + +QPushButton#revealLogButton { + background: url(resources/styles/txt-file.svg); + background-repeat: none; + background-position: left center; + background-origin: content; + padding-left: 10px; + background-color: #333333; + color: #BBBBBB; + border-width: 0; + border-radius: 9px; + font-size: 11px; +} + +QCheckBox::indicator:unchecked { + image: url(resources/styles/unchecked.svg); +} + +QCheckBox::indicator:checked { + image: url(resources/styles/checked.svg); } diff --git a/interface/resources/styles/search.svg b/interface/resources/styles/search.svg new file mode 100644 index 0000000000..b4701e8649 --- /dev/null +++ b/interface/resources/styles/search.svg @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/interface/resources/styles/txt-file.svg b/interface/resources/styles/txt-file.svg new file mode 100644 index 0000000000..1c25cc90a7 --- /dev/null +++ b/interface/resources/styles/txt-file.svg @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/interface/resources/styles/unchecked.svg b/interface/resources/styles/unchecked.svg new file mode 100644 index 0000000000..14f07c6625 --- /dev/null +++ b/interface/resources/styles/unchecked.svg @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/interface/src/LogDisplay.cpp b/interface/src/LogDisplay.cpp index dc365a9ea0..5713a9c0c5 100644 --- a/interface/src/LogDisplay.cpp +++ b/interface/src/LogDisplay.cpp @@ -156,13 +156,16 @@ void LogDisplay::addMessage(const char* ptr) { pthread_mutex_unlock(& _mutex); } -QStringList LogDisplay::getLogData() { +QStringList LogDisplay::getLogData(QString searchText) { // 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++]); + if (searchText.isEmpty() || QString(_lines[i]).contains(searchText, Qt::CaseInsensitive)) { + list.append(_lines[i]); + } + i++; } pthread_mutex_unlock(& _mutex); return list; diff --git a/interface/src/LogDisplay.h b/interface/src/LogDisplay.h index 285325b180..ea06c873f5 100644 --- a/interface/src/LogDisplay.h +++ b/interface/src/LogDisplay.h @@ -44,7 +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 - QStringList getLogData(); + QStringList getLogData(QString); signals: void logReceived(QString message); diff --git a/interface/src/ui/LogDialog.cpp b/interface/src/ui/LogDialog.cpp index 013c60d993..4d67e4ae00 100644 --- a/interface/src/ui/LogDialog.cpp +++ b/interface/src/ui/LogDialog.cpp @@ -14,7 +14,17 @@ #include "ui/LogDialog.h" #include "LogDisplay.h" -const int INITIAL_WIDTH = 720; +const int TOP_BAR_HEIGHT = 46; +const int INITIAL_WIDTH = 720; +const int MINIMAL_WIDTH = 570; +const int ELEMENT_MARGIN = 7; +const int ELEMENT_HEIGHT = 32; +const int SEARCH_BUTTON_LEFT = 25; +const int SEARCH_BUTTON_WIDTH = 20; +const int SEARCH_TEXT_WIDTH = 240; +const int CHECKBOX_MARGIN = 12; +const int CHECKBOX_WIDTH = 140; +const int REVEAL_BUTTON_WIDTH = 122; const float INITIAL_HEIGHT_RATIO = 0.6f; int cursorMeta = qRegisterMetaType("QTextCursor"); @@ -23,46 +33,85 @@ int blockMeta = qRegisterMetaType("QTextBlock"); LogDialog::LogDialog(QWidget* parent) : QDialog(parent, Qt::Dialog) { setWindowTitle("Log"); - - _logTextBox = new QPlainTextEdit(this); - _logTextBox->setReadOnly(true); - _logTextBox->show(); + setAttribute(Qt::WA_DeleteOnClose); switchToResourcesParentIfRequired(); QFile styleSheet("resources/styles/log_dialog.qss"); - if (styleSheet.open(QIODevice::ReadOnly)) { setStyleSheet(styleSheet.readAll()); } + initControls(); + 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); + setMinimumWidth(MINIMAL_WIDTH); } LogDialog::~LogDialog() { deleteLater(); } -void LogDialog::showEvent(QShowEvent *e) { - _logTextBox->clear(); +void LogDialog::initControls() { - pthread_mutex_lock(& _mutex); - QStringList _logData = LogDisplay::instance.getLogData(); + int left; + _searchButton = new QPushButton(this); + // set object name for css styling + _searchButton->setObjectName("searchButton"); + left = SEARCH_BUTTON_LEFT; + _searchButton->setGeometry(left, ELEMENT_MARGIN, SEARCH_BUTTON_WIDTH, ELEMENT_HEIGHT); + left += SEARCH_BUTTON_WIDTH; + _searchButton->show(); + connect(_searchButton, SIGNAL(clicked()), SLOT(handleSearchButton())); + + _searchTextBox = new QLineEdit(this); + // disable blue outline in Mac + _searchTextBox->setAttribute(Qt::WA_MacShowFocusRect, false); + _searchTextBox->setGeometry(left, ELEMENT_MARGIN, SEARCH_TEXT_WIDTH, ELEMENT_HEIGHT); + left += SEARCH_TEXT_WIDTH + CHECKBOX_MARGIN; + _searchTextBox->show(); + connect(_searchTextBox, SIGNAL(textChanged(QString)), SLOT(handleSeachTextChanged(QString))); + + _extraDebuggingBox = new QCheckBox("Extra debugging", this); + _extraDebuggingBox->setGeometry(left, ELEMENT_MARGIN, CHECKBOX_WIDTH, ELEMENT_HEIGHT); + _extraDebuggingBox->show(); + connect(_extraDebuggingBox, SIGNAL(stateChanged(int)), SLOT(handleExtraDebuggingCheckbox(int))); + + _revealLogButton = new QPushButton("Reveal log file", this); + // set object name for css styling + _revealLogButton->setObjectName("revealLogButton"); + _revealLogButton->show(); + connect(_revealLogButton, SIGNAL(clicked()), SLOT(handleRevealButton())); + + _logTextBox = new QPlainTextEdit(this); + _logTextBox->setReadOnly(true); + _logTextBox->show(); + +} + +void LogDialog::showEvent(QShowEvent *e) { + _searchTextBox->clear(); + _searchTextBox->setText(""); + +/* 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); + pthread_mutex_unlock(& _mutex);*/ } void LogDialog::resizeEvent(QResizeEvent *e) { - _logTextBox->resize(width(), height()); + _logTextBox->setGeometry(0, TOP_BAR_HEIGHT, width(), height() - TOP_BAR_HEIGHT); + _revealLogButton->setGeometry(width() - ELEMENT_MARGIN - REVEAL_BUTTON_WIDTH, + ELEMENT_MARGIN, + REVEAL_BUTTON_WIDTH, + ELEMENT_HEIGHT); } void LogDialog::appendLogLine(QString logLine) { @@ -73,3 +122,33 @@ void LogDialog::appendLogLine(QString logLine) { _logTextBox->ensureCursorVisible(); } } + +void LogDialog::handleSearchButton() { + _searchTextBox->setFocus(); +} + +void LogDialog::handleRevealButton() { + +} + +void LogDialog::handleExtraDebuggingCheckbox(int state) { + +} + +void LogDialog::handleSeachTextChanged(QString searchText) { + + if (searchText.isEmpty()) { + connect(&LogDisplay::instance, &LogDisplay::logReceived, this, &LogDialog::appendLogLine); + } else { + disconnect(&LogDisplay::instance, &LogDisplay::logReceived, this, &LogDialog::appendLogLine); + } + + _logTextBox->clear(); + pthread_mutex_lock(& _mutex); + QStringList _logData = LogDisplay::instance.getLogData(searchText); + for(int i = 0; i < _logData.size(); ++i) { + appendLogLine(_logData[i]); + } + + pthread_mutex_unlock(& _mutex); +} diff --git a/interface/src/ui/LogDialog.h b/interface/src/ui/LogDialog.h index 808ac4a485..741d4b1845 100644 --- a/interface/src/ui/LogDialog.h +++ b/interface/src/ui/LogDialog.h @@ -11,6 +11,9 @@ #include #include +#include +#include +#include class LogDialog : public QDialog { Q_OBJECT @@ -22,14 +25,25 @@ public: public slots: void appendLogLine(QString logLine); +private slots: + void handleSearchButton(); + void handleRevealButton(); + void handleExtraDebuggingCheckbox(const int); + void handleSeachTextChanged(QString); + protected: - void resizeEvent(QResizeEvent* e); - void showEvent(QShowEvent* e); + void resizeEvent(QResizeEvent*); + void showEvent(QShowEvent*); private: + QPushButton* _searchButton; + QLineEdit* _searchTextBox; + QCheckBox* _extraDebuggingBox; + QPushButton* _revealLogButton; QPlainTextEdit* _logTextBox; pthread_mutex_t _mutex; + void initControls(); }; #endif