1
0
Fork 0

GUI: separated DebugStatusLabel from LogStatusLabel

This commit is contained in:
mrexodia 2016-09-27 16:05:13 +02:00
parent 87319baf61
commit a309a96de9
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
9 changed files with 128 additions and 98 deletions

View File

@ -0,0 +1,54 @@
#include "DebugStatusLabel.h"
#include <QTextDocument>
DebugStatusLabel::DebugStatusLabel(QStatusBar* parent) : QLabel(parent)
{
this->setFrameStyle(QFrame::Sunken | QFrame::Panel); //sunken style
this->setStyleSheet("QLabel { background-color : #C0C0C0; }");
statusTexts[0] = tr("Initialized");
statusTexts[1] = tr("Paused");
statusTexts[2] = tr("Running");
statusTexts[3] = tr("Terminated");
QFontMetrics fm(this->font());
int maxWidth = 0;
for(size_t i = 0; i < _countof(statusTexts); i++)
{
int width = fm.width(statusTexts[i]);
if(width > maxWidth)
maxWidth = width;
}
this->setTextFormat(Qt::RichText); //rich text
parent->setStyleSheet("QStatusBar { background-color: #C0C0C0; } QStatusBar::item { border: none; }");
this->setFixedHeight(parent->height());
this->setAlignment(Qt::AlignCenter);
this->setFixedWidth(maxWidth + 10);
connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(debugStateChangedSlot(DBGSTATE)));
}
void DebugStatusLabel::debugStateChangedSlot(DBGSTATE state)
{
switch(state)
{
case initialized:
this->setText(QString("<font color='#00DD00'>%1</font>").arg(statusTexts[state]));
this->setStyleSheet("QLabel { background-color : #C0C0C0; }");
break;
case paused:
this->setText(QString("<font color='#FF0000'>%1</font>").arg(statusTexts[state]));
this->setStyleSheet("QLabel { background-color : #FFFF00; }");
break;
case running:
this->setText(QString("<font color='#000000'>%1</font>").arg(statusTexts[state]));
this->setStyleSheet("QLabel { background-color : #C0C0C0; }");
break;
case stopped:
this->setText(QString("<font color='#FF0000'>%1</font>").arg(statusTexts[state]));
this->setStyleSheet("QLabel { background-color : #C0C0C0; }");
GuiUpdateWindowTitle("");
break;
}
this->update();
}

View File

@ -5,18 +5,16 @@
#include <QStatusBar>
#include "Bridge.h"
class StatusLabel : public QLabel
class DebugStatusLabel : public QLabel
{
Q_OBJECT
public:
explicit StatusLabel(QStatusBar* parent = 0);
explicit DebugStatusLabel(QStatusBar* parent = 0);
public slots:
void debugStateChangedSlot(DBGSTATE state);
void logUpdate(QString message);
private:
QString labelText;
QString statusTexts[4];
};

View File

@ -0,0 +1,33 @@
#include "LogStatusLabel.h"
#include <QTextDocument>
LogStatusLabel::LogStatusLabel(QStatusBar* parent) : QLabel(parent)
{
this->setFrameStyle(QFrame::Sunken | QFrame::Panel); //sunken style
this->setStyleSheet("QLabel { background-color : #C0C0C0; }");
this->setTextFormat(Qt::PlainText);
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
connect(Bridge::getBridge(), SIGNAL(addMsgToLog(QString)), this, SLOT(logUpdate(QString)));
connect(Bridge::getBridge(), SIGNAL(addMsgToStatusBar(QString)), this, SLOT(logUpdate(QString)));
}
void LogStatusLabel::logUpdate(QString message)
{
if(!message.length())
return;
labelText += message.replace("\r\n", "\n");
QStringList lineList = labelText.split('\n');
labelText = lineList.last(); //if the last character is a newline this will be an empty string
QString finalLabel;
for(int i = 0; i < lineList.length(); i++)
{
const QString & line = lineList[lineList.size() - i - 1];
if(line.length()) //set the last non-empty string from the split
{
finalLabel = line;
break;
}
}
setText(finalLabel);
}

View File

@ -0,0 +1,21 @@
#ifndef LOGSTATUSLABEL_H
#define LOGSTATUSLABEL_H
#include <QLabel>
#include <QStatusBar>
#include "Bridge.h"
class LogStatusLabel : public QLabel
{
Q_OBJECT
public:
explicit LogStatusLabel(QStatusBar* parent = 0);
public slots:
void logUpdate(QString message);
private:
QString labelText;
};
#endif // LOGSTATUSLABEL_H

View File

@ -31,7 +31,8 @@
#include "ThreadView.h"
#include "PatchDialog.h"
#include "CalculatorDialog.h"
#include "StatusLabel.h"
#include "DebugStatusLabel.h"
#include "LogStatusLabel.h"
#include "UpdateChecker.h"
#include "SourceViewerManager.h"
#include "SnowmanView.h"
@ -379,12 +380,12 @@ void MainWindow::setupCommandBar()
void MainWindow::setupStatusBar()
{
// Status label (Ready, Paused, ...)
mStatusLabel = new StatusLabel(ui->statusBar);
mStatusLabel = new DebugStatusLabel(ui->statusBar);
mStatusLabel->setText(tr("Ready"));
ui->statusBar->addWidget(mStatusLabel);
// Log line
mLastLogLabel = new StatusLabel();
mLastLogLabel = new LogStatusLabel(ui->statusBar);
ui->statusBar->addPermanentWidget(mLastLogLabel, 1);
// Time wasted counter

View File

@ -21,7 +21,8 @@ class ReferenceManager;
class ThreadView;
class PatchDialog;
class CalculatorDialog;
class StatusLabel;
class DebugStatusLabel;
class LogStatusLabel;
class UpdateChecker;
class SourceViewerManager;
class SnowmanView;
@ -163,8 +164,8 @@ private:
NotesManager* mNotesManager;
DisassemblerGraphView* mGraphView;
StatusLabel* mStatusLabel;
StatusLabel* mLastLogLabel;
DebugStatusLabel* mStatusLabel;
LogStatusLabel* mLastLogLabel;
UpdateChecker* mUpdateChecker;
TimeWastedCounter* mTimeWastedCounter;

View File

@ -1,82 +0,0 @@
#include "StatusLabel.h"
#include <QTextDocument>
StatusLabel::StatusLabel(QStatusBar* parent) : QLabel(parent)
{
this->setFrameStyle(QFrame::Sunken | QFrame::Panel); //sunken style
this->setStyleSheet("QLabel { background-color : #C0C0C0; }");
if(parent) //the debug-status label only has a parent
{
statusTexts[0] = tr("Initialized");
statusTexts[1] = tr("Paused");
statusTexts[2] = tr("Running");
statusTexts[3] = tr("Terminated");
QFontMetrics fm(this->font());
int maxWidth = 0;
for(size_t i = 0; i < _countof(statusTexts); i++)
{
int width = fm.width(statusTexts[i]);
if(width > maxWidth)
maxWidth = width;
}
this->setTextFormat(Qt::RichText); //rich text
parent->setStyleSheet("QStatusBar { background-color: #C0C0C0; } QStatusBar::item { border: none; }");
this->setFixedHeight(parent->height());
this->setAlignment(Qt::AlignCenter);
this->setFixedWidth(maxWidth + 10);
connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(debugStateChangedSlot(DBGSTATE)));
}
else //last log message
{
this->setTextFormat(Qt::PlainText);
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
connect(Bridge::getBridge(), SIGNAL(addMsgToLog(QString)), this, SLOT(logUpdate(QString)));
connect(Bridge::getBridge(), SIGNAL(addMsgToStatusBar(QString)), this, SLOT(logUpdate(QString)));
}
}
void StatusLabel::debugStateChangedSlot(DBGSTATE state)
{
switch(state)
{
case initialized:
this->setText(QString("<font color='#00DD00'>%1</font>").arg(statusTexts[state]));
this->setStyleSheet("QLabel { background-color : #C0C0C0; }");
break;
case paused:
this->setText(QString("<font color='#FF0000'>%1</font>").arg(statusTexts[state]));
this->setStyleSheet("QLabel { background-color : #FFFF00; }");
break;
case running:
this->setText(QString("<font color='#000000'>%1</font>").arg(statusTexts[state]));
this->setStyleSheet("QLabel { background-color : #C0C0C0; }");
break;
case stopped:
this->setText(QString("<font color='#FF0000'>%1</font>").arg(statusTexts[state]));
this->setStyleSheet("QLabel { background-color : #C0C0C0; }");
GuiUpdateWindowTitle("");
break;
}
this->update();
}
void StatusLabel::logUpdate(QString message)
{
if(!message.length())
return;
labelText += message.replace("\r\n", "\n");
QStringList lineList = labelText.split('\n');
labelText = lineList.last(); //if the last character is a newline this will be an empty string
QString finalLabel;
for(int i = 0; i < lineList.length(); i++)
{
const QString & line = lineList[lineList.size() - i - 1];
if(line.length()) //set the last non-empty string from the split
{
finalLabel = line;
break;
}
}
setText(finalLabel);
}

View File

@ -89,7 +89,6 @@ SOURCES += \
Src/Gui/MemoryMapView.cpp \
Src/Gui/LogView.cpp \
Src/Gui/GotoDialog.cpp \
Src/Gui/StatusLabel.cpp \
Src/Gui/WordEditDialog.cpp \
Src/Gui/CPUDisassembly.cpp \
Src/Gui/LineEditDialog.cpp \
@ -170,7 +169,9 @@ SOURCES += \
Src/Gui/DisassemblyPopup.cpp \
Src/Gui/VirtualModDialog.cpp \
Src/BasicView/LabeledSplitter.cpp \
Src/BasicView/LabeledSplitterDetachedWindow.cpp
Src/BasicView/LabeledSplitterDetachedWindow.cpp \
Src/Gui/LogStatusLabel.cpp \
Src/Gui/DebugStatusLabel.cpp
HEADERS += \
@ -192,7 +193,6 @@ HEADERS += \
Src/Gui/LogView.h \
Src/Gui/GotoDialog.h \
Src/Gui/RegistersView.h \
Src/Gui/StatusLabel.h \
Src/Gui/WordEditDialog.h \
Src/Gui/CPUDisassembly.h \
Src/Gui/LineEditDialog.h \
@ -277,7 +277,9 @@ HEADERS += \
Src/Gui/DisassemblyPopup.h \
Src/Gui/VirtualModDialog.h \
Src/BasicView/LabeledSplitter.h \
Src/BasicView/LabeledSplitterDetachedWindow.h
Src/BasicView/LabeledSplitterDetachedWindow.h \
Src/Gui/LogStatusLabel.h \
Src/Gui/DebugStatusLabel.h
FORMS += \

View File

@ -55,7 +55,8 @@ SOURCES += \
gui/Src/Gui/ShortcutsDialog.cpp \
gui/Src/Gui/SourceView.cpp \
gui/Src/Gui/SourceViewerManager.cpp \
gui/Src/Gui/StatusLabel.cpp \
gui/Src/Gui/DebugStatusLabel.cpp \
gui/Src/Gui/LogStatusLabel.cpp \
gui/Src/Gui/SymbolView.cpp \
gui/Src/Gui/TabBar.cpp \
gui/Src/Gui/TabWidget.cpp \
@ -267,7 +268,8 @@ HEADERS += \
gui/Src/Gui/ShortcutsDialog.h \
gui/Src/Gui/SourceView.h \
gui/Src/Gui/SourceViewerManager.h \
gui/Src/Gui/StatusLabel.h \
gui/Src/Gui/DebugStatusLabel.h \
gui/Src/Gui/LogStatusLabel.h \
gui/Src/Gui/SymbolView.h \
gui/Src/Gui/TabBar.h \
gui/Src/Gui/TabWidget.h \