Add animated icons to LogsWindow tab
This commit is contained in:
parent
10dddf410a
commit
95578e5094
BIN
client/icons/anime_error.gif
Normal file
BIN
client/icons/anime_error.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
BIN
client/icons/anime_warn.gif
Normal file
BIN
client/icons/anime_warn.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
@ -24,6 +24,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QMovie>
|
||||||
|
|
||||||
|
extern QMainWindow *mainWindow;
|
||||||
|
|
||||||
LogsWindow::LogsWindow(LogsModel *model, QWidget *parent)
|
LogsWindow::LogsWindow(LogsModel *model, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
@ -42,6 +46,9 @@ LogsWindow::LogsWindow(LogsModel *model, QWidget *parent)
|
|||||||
parentDock_ = qobject_cast<QDockWidget*>(parent);
|
parentDock_ = qobject_cast<QDockWidget*>(parent);
|
||||||
windowTitle_ = parentDock_->windowTitle();
|
windowTitle_ = parentDock_->windowTitle();
|
||||||
|
|
||||||
|
warnAnime_ = new QMovie(":/icons/anime_warn.gif", QByteArray(), this);
|
||||||
|
errorAnime_ = new QMovie(":/icons/anime_error.gif", QByteArray(), this);
|
||||||
|
|
||||||
connect(level, SIGNAL(currentIndexChanged(int)),
|
connect(level, SIGNAL(currentIndexChanged(int)),
|
||||||
model, SLOT(setLogLevel(int)));
|
model, SLOT(setLogLevel(int)));
|
||||||
connect(clear, SIGNAL(clicked()), model, SLOT(clear()));
|
connect(clear, SIGNAL(clicked()), model, SLOT(clear()));
|
||||||
@ -60,14 +67,16 @@ LogsWindow::LogsWindow(LogsModel *model, QWidget *parent)
|
|||||||
|
|
||||||
LogsWindow::~LogsWindow()
|
LogsWindow::~LogsWindow()
|
||||||
{
|
{
|
||||||
|
delete warnAnime_;
|
||||||
|
delete errorAnime_;
|
||||||
delete logsModelTest_;
|
delete logsModelTest_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogsWindow::when_visibilityChanged(bool visible)
|
void LogsWindow::when_visibilityChanged(bool visible)
|
||||||
{
|
{
|
||||||
if (visible) {
|
if (visible) {
|
||||||
parentDock_->setWindowTitle(windowTitle_);
|
state_ = kInfo;
|
||||||
annotation_.clear();
|
notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
isVisible_ = visible;
|
isVisible_ = visible;
|
||||||
@ -80,7 +89,7 @@ void LogsWindow::when_rowsInserted(const QModelIndex &parent,
|
|||||||
if (isVisible_)
|
if (isVisible_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (annotation_.contains("Error"))
|
if (state_ == kError)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = first; i <= last; i++) {
|
for (int i = first; i <= last; i++) {
|
||||||
@ -89,14 +98,14 @@ void LogsWindow::when_rowsInserted(const QModelIndex &parent,
|
|||||||
QString level = logs->model()->data(logs->model()->index(i, 1, parent))
|
QString level = logs->model()->data(logs->model()->index(i, 1, parent))
|
||||||
.toString();
|
.toString();
|
||||||
if (level == "Error") {
|
if (level == "Error") {
|
||||||
annotation_ = QString(" - Error(s)");
|
state_ = kError;
|
||||||
break; // Highest level - no need to look further
|
break; // Highest level - no need to look further
|
||||||
}
|
}
|
||||||
else if (level == "Warning") {
|
else if (level == "Warning") {
|
||||||
annotation_ = QString(" - Warning(s)");
|
state_ = kWarning;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parentDock_->setWindowTitle(windowTitle_+annotation_);
|
notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogsWindow::on_autoScroll_toggled(bool checked)
|
void LogsWindow::on_autoScroll_toggled(bool checked)
|
||||||
@ -112,3 +121,60 @@ void LogsWindow::on_autoScroll_toggled(bool checked)
|
|||||||
logs, SLOT(scrollToBottom()));
|
logs, SLOT(scrollToBottom()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QLabel* LogsWindow::tabIcon()
|
||||||
|
{
|
||||||
|
QList<QTabBar*> tabBars = mainWindow->findChildren<QTabBar*>();
|
||||||
|
foreach(QTabBar* tabBar, tabBars) {
|
||||||
|
for (int i = 0; i < tabBar->count(); i++) {
|
||||||
|
if (tabBar->tabText(i).startsWith(windowTitle_)) {
|
||||||
|
QLabel *icon = qobject_cast<QLabel*>(
|
||||||
|
tabBar->tabButton(i, QTabBar::LeftSide));
|
||||||
|
if (!icon) { // Lazy create
|
||||||
|
icon = new QLabel();
|
||||||
|
tabBar->setTabButton(i, QTabBar::LeftSide, icon);
|
||||||
|
}
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogsWindow::notify()
|
||||||
|
{
|
||||||
|
QString annotation;
|
||||||
|
QMovie *anime = nullptr;
|
||||||
|
|
||||||
|
// Stop all animations before we start a new one
|
||||||
|
warnAnime_->stop();
|
||||||
|
errorAnime_->stop();
|
||||||
|
|
||||||
|
switch (state_) {
|
||||||
|
case kError:
|
||||||
|
anime = errorAnime_;
|
||||||
|
annotation = " - Error(s)";
|
||||||
|
break;
|
||||||
|
case kWarning:
|
||||||
|
anime = warnAnime_;
|
||||||
|
annotation = " - Warning(s)";
|
||||||
|
break;
|
||||||
|
case kInfo:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel *icon = tabIcon(); // NOTE: we may not have a icon if not tabified
|
||||||
|
if (icon) {
|
||||||
|
if (anime) {
|
||||||
|
icon->setMovie(anime);
|
||||||
|
anime->start();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
icon->clear();
|
||||||
|
icon->adjustSize();
|
||||||
|
}
|
||||||
|
parentDock_->setWindowTitle(windowTitle_ + annotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
class LogsModel;
|
class LogsModel;
|
||||||
class QDockWidget;
|
class QDockWidget;
|
||||||
class QShowEvent;
|
class QShowEvent;
|
||||||
|
class QMovie;
|
||||||
|
|
||||||
class LogsWindow: public QWidget, private Ui::LogsWindow
|
class LogsWindow: public QWidget, private Ui::LogsWindow
|
||||||
{
|
{
|
||||||
@ -39,9 +40,16 @@ private slots:
|
|||||||
void on_autoScroll_toggled(bool checked);
|
void on_autoScroll_toggled(bool checked);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum State {kInfo, kWarning, kError};
|
||||||
|
|
||||||
|
QLabel* tabIcon();
|
||||||
|
void notify();
|
||||||
|
|
||||||
|
State state_{kInfo};
|
||||||
QDockWidget *parentDock_;
|
QDockWidget *parentDock_;
|
||||||
|
QMovie *warnAnime_{nullptr};
|
||||||
|
QMovie *errorAnime_{nullptr};
|
||||||
QString windowTitle_;
|
QString windowTitle_;
|
||||||
QString annotation_;
|
|
||||||
bool isVisible_{false};
|
bool isVisible_{false};
|
||||||
QObject *logsModelTest_;
|
QObject *logsModelTest_;
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>icons/about.png</file>
|
<file>icons/about.png</file>
|
||||||
<file>icons/add.png</file>
|
<file>icons/add.png</file>
|
||||||
|
<file>icons/anime_error.gif</file>
|
||||||
|
<file>icons/anime_warn.gif</file>
|
||||||
<file>icons/arrow_down.png</file>
|
<file>icons/arrow_down.png</file>
|
||||||
<file>icons/arrow_left.png</file>
|
<file>icons/arrow_left.png</file>
|
||||||
<file>icons/arrow_right.png</file>
|
<file>icons/arrow_right.png</file>
|
||||||
|
Loading…
Reference in New Issue
Block a user