|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/tmessageviewer.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/dvdialog.h"
|
|
Toshihiro Shimizu |
890ddd |
#include <qvboxlayout></qvboxlayout>
|
|
Toshihiro Shimizu |
890ddd |
#include <qpushbutton></qpushbutton>
|
|
Toshihiro Shimizu |
890ddd |
#include <qlistview></qlistview>
|
|
Toshihiro Shimizu |
890ddd |
#include <qstandarditemmodel></qstandarditemmodel>
|
|
Toshihiro Shimizu |
890ddd |
#include <qsortfilterproxymodel></qsortfilterproxymodel>
|
|
Toshihiro Shimizu |
890ddd |
#include <qcheckbox></qcheckbox>
|
|
Toshihiro Shimizu |
890ddd |
#include <qlabel></qlabel>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QIcon gRedIcon;
|
|
Toshihiro Shimizu |
890ddd |
QIcon gGreenIcon;
|
|
Toshihiro Shimizu |
890ddd |
QIcon gYellowIcon;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class MyQListView final : public QListView {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
MyQListView(QWidget *parent) : QListView(parent) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
473e70 |
void rowsInserted(const QModelIndex &parent, int start, int end) override {
|
|
Shinya Kitaoka |
120a6e |
QListView::rowsInserted(parent, start, end);
|
|
Shinya Kitaoka |
120a6e |
scrollToBottom();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class MySortFilterProxyModel final : public QSortFilterProxyModel {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
MySortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
38fd86 |
bool filterAcceptsRow(int sourceRow,
|
|
Shinya Kitaoka |
38fd86 |
const QModelIndex &sourceParent) const override {
|
|
Shinya Kitaoka |
120a6e |
TMessageViewer *v = dynamic_cast<tmessageviewer *="">(parent());</tmessageviewer>
|
|
Shinya Kitaoka |
120a6e |
assert(v);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QIcon ic = ((QStandardItemModel *)sourceModel())->item(sourceRow)->icon();
|
|
Shinya Kitaoka |
120a6e |
if (ic.cacheKey() == gGreenIcon.cacheKey())
|
|
Shinya Kitaoka |
120a6e |
return v->m_greenCheck->isChecked();
|
|
Shinya Kitaoka |
120a6e |
else if (ic.cacheKey() == gYellowIcon.cacheKey())
|
|
Shinya Kitaoka |
120a6e |
return v->m_yellowCheck->isChecked();
|
|
Shinya Kitaoka |
120a6e |
else if (ic.cacheKey() == gRedIcon.cacheKey())
|
|
Shinya Kitaoka |
120a6e |
return v->m_redCheck->isChecked();
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TMessageViewer::onClicked(bool) {
|
|
Shinya Kitaoka |
120a6e |
TMessageRepository::instance()->clear();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/*return;
|
|
Shinya Kitaoka |
120a6e |
static int count=0;
|
|
Shinya Kitaoka |
120a6e |
count++;
|
|
Shinya Kitaoka |
120a6e |
DVGui::MsgBox((count%3)==1?INFORMATION:(count%3)==2?WARNING:CRITICAL,
|
|
Shinya Kitaoka |
120a6e |
"messaggio "+QString::number(count));*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TMessageViewer::refreshFilter(int) { m_proxyModel->invalidate(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TMessageRepository::clear() { m_sim->clear(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TMessageRepository::TMessageRepository() : m_sim(new QStandardItemModel()) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TMessageRepository *TMessageRepository::instance() {
|
|
Shinya Kitaoka |
120a6e |
static TMessageRepository *theObject = 0;
|
|
Shinya Kitaoka |
120a6e |
if (theObject == 0) {
|
|
Shinya Kitaoka |
120a6e |
theObject = new TMessageRepository();
|
|
Shinya Kitaoka |
120a6e |
bool ret =
|
|
Shinya Kitaoka |
120a6e |
connect(TMsgCore::instance(), SIGNAL(sendMessage(int, const QString &)),
|
|
Shinya Kitaoka |
120a6e |
theObject, SLOT(messageReceived(int, const QString &)));
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Shinya Kitaoka |
120a6e |
// TMsgCore::instance()->getConnectionName();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return theObject;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TMessageRepository::messageReceived(int type, const QString &message) {
|
|
Shinya Kitaoka |
120a6e |
if (gRedIcon.isNull()) {
|
|
shun_iwasawa |
3cc41f |
gRedIcon = QIcon(":Resources/tmsg_error.svg");
|
|
shun_iwasawa |
3cc41f |
gYellowIcon = QIcon(":Resources/tmsg_warning.svg");
|
|
shun_iwasawa |
3cc41f |
gGreenIcon = QIcon(":Resources/tmsg_info.svg");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
switch (type) {
|
|
Shinya Kitaoka |
120a6e |
case DVGui::INFORMATION:
|
|
Shinya Kitaoka |
120a6e |
m_sim->appendRow(new QStandardItem(gGreenIcon, message));
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case DVGui::WARNING:
|
|
Shinya Kitaoka |
120a6e |
m_sim->appendRow(new QStandardItem(gYellowIcon, message));
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case DVGui::CRITICAL:
|
|
Shinya Kitaoka |
120a6e |
m_sim->appendRow(new QStandardItem(gRedIcon, message));
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (type == DVGui::CRITICAL ||
|
|
Shinya Kitaoka |
120a6e |
(type == DVGui::WARNING && !TMessageViewer::isTMsgVisible()))
|
|
Shinya Kitaoka |
120a6e |
DVGui::MsgBoxInPopup(DVGui::MsgType(type), message);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tmessageviewer *=""> TMessageViewer::m_tmsgViewers;</tmessageviewer>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TMessageViewer::isTMsgVisible() {
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)m_tmsgViewers.size(); i++)
|
|
Shinya Kitaoka |
120a6e |
if (m_tmsgViewers[i]->isVisible()) return true;
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TMessageViewer::TMessageViewer(QWidget *parent) : QFrame(parent) {
|
|
Shinya Kitaoka |
120a6e |
m_tmsgViewers.push_back(this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
Shinya Kitaoka |
120a6e |
setFrameStyle(QFrame::StyledPanel);
|
|
Shinya Kitaoka |
120a6e |
setObjectName("OnePixelMarginFrame");
|
|
Shinya Kitaoka |
120a6e |
QVBoxLayout *vLayout = new QVBoxLayout();
|
|
Shinya Kitaoka |
120a6e |
vLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
QFrame *fr = new QFrame();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QHBoxLayout *hLayout = new QHBoxLayout();
|
|
Shinya Kitaoka |
120a6e |
hLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
fr->setLayout(hLayout);
|
|
Shinya Kitaoka |
120a6e |
fr->setFixedHeight(24);
|
|
shun_iwasawa |
d4973a |
fr->setStyleSheet("background-color: rgb(210,210,210); color: black;");
|
|
Shinya Kitaoka |
120a6e |
hLayout->addSpacing(4);
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
d4973a |
hLayout->addWidget(new QLabel(tr("Display: ")));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_redCheck = new QCheckBox(tr("Errors"));
|
|
Shinya Kitaoka |
120a6e |
m_redCheck->setChecked(true);
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_redCheck, SIGNAL(stateChanged(int)),
|
|
Shinya Kitaoka |
120a6e |
SLOT(refreshFilter(int)));
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(m_redCheck);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_yellowCheck = new QCheckBox(tr("Warnings"));
|
|
Shinya Kitaoka |
120a6e |
m_yellowCheck->setChecked(true);
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_yellowCheck, SIGNAL(stateChanged(int)),
|
|
Shinya Kitaoka |
120a6e |
SLOT(refreshFilter(int)));
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(m_yellowCheck);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jeremy Bullock |
934e82 |
m_greenCheck = new QCheckBox(tr("Info"));
|
|
Shinya Kitaoka |
120a6e |
m_greenCheck->setChecked(true);
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_greenCheck, SIGNAL(stateChanged(int)),
|
|
Shinya Kitaoka |
120a6e |
SLOT(refreshFilter(int)));
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(m_greenCheck);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
hLayout->addStretch();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QPushButton *pb = new QPushButton(tr(" Clear "));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(pb, SIGNAL(clicked(bool)), SLOT(onClicked(bool)));
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(pb);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
hLayout->addSpacing(4);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
vLayout->addWidget(fr);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
MyQListView *lv = new MyQListView(this);
|
|
Shinya Kitaoka |
120a6e |
lv->setAlternatingRowColors(true);
|
|
Shinya Kitaoka |
120a6e |
lv->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
Shinya Kitaoka |
120a6e |
lv->setAutoScroll(true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_proxyModel = new MySortFilterProxyModel(this);
|
|
Shinya Kitaoka |
120a6e |
m_proxyModel->setDynamicSortFilter(true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_proxyModel->setSourceModel(TMessageRepository::instance()->getModel());
|
|
Shinya Kitaoka |
120a6e |
lv->setModel(m_proxyModel);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
vLayout->addWidget(lv);
|
|
Shinya Kitaoka |
120a6e |
setLayout(vLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|