-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathStatusBarWidget.cpp
92 lines (76 loc) · 2.86 KB
/
StatusBarWidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "StatusBarWidget.h"
#include <QDebug>
#include <QResizeEvent>
#include <QStatusBar>
// ui
#include <ui_StatusBarWidget.h>
namespace shapeworks {
//---------------------------------------------------------------------------
StatusBarWidget::StatusBarWidget(QMainWindow* parent) : QWidget(parent) {
ui_ = new Ui_StatusBarWidget;
ui_->setupUi(this);
normal_message_icon_.addFile(QString::fromUtf8(":/Studio/Images/log_normal.png"), QSize(), QIcon::Normal);
error_message_icon_.addFile(QString::fromUtf8(":/Studio/Images/log_error.png"), QSize(), QIcon::Normal);
warning_message_icon_.addFile(QString::fromUtf8(":/Studio/Images/log_warning.png"), QSize(), QIcon::Normal);
q_status_bar_ = parent->statusBar();
q_status_bar_->setContentsMargins(0, 0, 0, 0);
q_status_bar_->addWidget(this, 1);
ui_->log_button->setIcon(normal_message_icon_);
ui_->progress_bar->setVisible(false);
connect(ui_->log_button, &QToolButton::clicked, this, &StatusBarWidget::toggle_log_window);
}
//---------------------------------------------------------------------------
void StatusBarWidget::set_message(MessageType message_type, QString message) {
message.replace('\n', ' ');
// truncate long messages
if (message.length() > 100) {
message.truncate(100);
message = message + "...";
}
if (message_type == MessageType::normal) {
ui_->log_button->setIcon(normal_message_icon_);
} else if (message_type == MessageType::warning) {
ui_->log_button->setIcon(warning_message_icon_);
} else if (message_type == MessageType::debug) {
ui_->log_button->setIcon(normal_message_icon_);
message = "<font color=#800080>" + message + "</font>";
} else {
ui_->log_button->setIcon(error_message_icon_);
message = "<font color=#CC0000>" + message + "</font>";
}
ui_->message->setText(message);
update_layout();
}
//---------------------------------------------------------------------------
void StatusBarWidget::set_progress(int value) {
if (value < 0) {
ui_->progress_bar->setVisible(true);
ui_->progress_bar->setMinimum(0);
ui_->progress_bar->setMaximum(0);
return;
}
ui_->progress_bar->setMinimum(0);
ui_->progress_bar->setMaximum(100);
if (value < 100) {
ui_->progress_bar->setVisible(true);
ui_->progress_bar->setValue(value);
} else {
ui_->progress_bar->setValue(100);
ui_->progress_bar->setVisible(false);
}
update_layout();
}
//---------------------------------------------------------------------------
void StatusBarWidget::resizeEvent(QResizeEvent* event) {
QWidget::resizeEvent(event);
update_layout();
}
//---------------------------------------------------------------------------
void StatusBarWidget::update_layout() {
if (ui_->progress_bar->isVisible()) {
ui_->message->setMaximumWidth(width() * 0.66);
} else {
ui_->message->setMaximumWidth(width() * 1.0);
}
}
} // namespace shapeworks