2009-12-22 10:04:30 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file GuiProgressView.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Peter Kümmel
|
2009-12-29 15:05:37 +00:00
|
|
|
* \author Pavel Sanda
|
2009-12-22 10:04:30 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "GuiProgressView.h"
|
2009-12-28 22:02:41 +00:00
|
|
|
#include "GuiApplication.h"
|
2009-12-22 10:04:30 +00:00
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
2009-12-30 17:15:00 +00:00
|
|
|
#include "FuncRequest.h"
|
2009-12-22 10:04:30 +00:00
|
|
|
|
2009-12-25 16:52:03 +00:00
|
|
|
#include "support/debug.h"
|
2009-12-30 17:15:00 +00:00
|
|
|
#include "support/convert.h"
|
2009-12-25 16:52:03 +00:00
|
|
|
|
2009-12-28 21:55:50 +00:00
|
|
|
#include <QSettings>
|
2009-12-22 10:33:01 +00:00
|
|
|
#include <QTime>
|
2009-12-30 14:48:47 +00:00
|
|
|
|
|
|
|
#include <QCheckBox>
|
2010-01-05 22:32:58 +00:00
|
|
|
#include <QDebug>
|
2009-12-30 14:48:47 +00:00
|
|
|
|
2010-01-04 17:12:50 +00:00
|
|
|
using namespace std;
|
|
|
|
using namespace lyx::support;
|
2009-12-22 10:04:30 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
2009-12-30 14:48:47 +00:00
|
|
|
struct LevelButton : QCheckBox
|
2009-12-29 15:05:37 +00:00
|
|
|
{
|
2009-12-30 14:48:47 +00:00
|
|
|
LevelButton(const QString& name) : QCheckBox(name) {}
|
2009-12-29 15:05:37 +00:00
|
|
|
Debug::Type level;
|
2010-01-06 06:49:49 +00:00
|
|
|
|
|
|
|
void setCheckStatusSilent(Qt::CheckState state) {
|
|
|
|
blockSignals(true);
|
|
|
|
setCheckState(state);
|
|
|
|
blockSignals(false);
|
|
|
|
}
|
2009-12-29 15:05:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-12-28 21:40:14 +00:00
|
|
|
ProgressViewWidget::ProgressViewWidget()
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GuiProgressView::~GuiProgressView()
|
|
|
|
{
|
|
|
|
delete widget_;
|
|
|
|
}
|
2009-12-22 10:04:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
|
2009-12-28 21:40:14 +00:00
|
|
|
Qt::WindowFlags flags) : DockView(parent, "progress", "Debug/Progress window", area, flags)
|
2009-12-22 10:04:30 +00:00
|
|
|
{
|
2009-12-28 21:40:14 +00:00
|
|
|
widget_ = new ProgressViewWidget();
|
|
|
|
setWidget(widget_);
|
2009-12-22 10:04:30 +00:00
|
|
|
|
2009-12-28 22:02:41 +00:00
|
|
|
QFont font(guiApp->typewriterFontName());
|
|
|
|
font.setKerning(false);
|
|
|
|
font.setFixedPitch(true);
|
|
|
|
font.setStyleHint(QFont::TypeWriter);
|
|
|
|
widget_->outTE->setFont(font);
|
2010-01-03 17:26:46 +00:00
|
|
|
widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
|
2009-12-28 22:02:41 +00:00
|
|
|
|
2010-01-05 22:32:58 +00:00
|
|
|
toggle_button = new LevelButton("Toggle ALL messages");
|
|
|
|
toggle_button->level = Debug::ANY;
|
|
|
|
toggle_button->setTristate(true);
|
|
|
|
toggle_button->setCheckState(Qt::PartiallyChecked);
|
|
|
|
widget_->settingsLayout->addWidget(toggle_button);
|
|
|
|
connect(toggle_button, SIGNAL(stateChanged(int)), this, SLOT(tristateChanged(int)));
|
|
|
|
|
|
|
|
// ignore Debug::NONE and Debug::ANY
|
|
|
|
int const level_count = Debug::levelCount() - 1;
|
|
|
|
for (int i = 1 ; i < level_count; i++) {
|
2010-01-04 17:12:50 +00:00
|
|
|
Debug::Type const level = Debug::value(i);
|
2009-12-30 15:09:49 +00:00
|
|
|
LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
|
|
|
|
box->level = level;
|
2010-01-04 17:12:50 +00:00
|
|
|
widget_->settingsLayout->addWidget(box, (i + 3) % 10, (i + 3) / 10);
|
2010-01-04 17:31:06 +00:00
|
|
|
box->setChecked(false);
|
2009-12-30 14:48:47 +00:00
|
|
|
level_buttons << box;
|
2009-12-30 15:09:49 +00:00
|
|
|
connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
2010-01-04 17:14:08 +00:00
|
|
|
widget_->settingsLayout->activate();
|
2010-01-04 17:12:50 +00:00
|
|
|
|
|
|
|
GuiProgress * progress =
|
|
|
|
dynamic_cast<GuiProgress *>(ProgressInterface::instance());
|
2009-12-22 10:04:30 +00:00
|
|
|
|
|
|
|
if (progress) {
|
2010-01-04 17:12:50 +00:00
|
|
|
connect(progress, SIGNAL(processStarted(QString const &)),
|
|
|
|
this, SLOT(appendText(QString const &)));
|
|
|
|
//connect(progress, SIGNAL(processFinished(QString const &)),
|
|
|
|
// this, SLOT(appendText(QString const &)));
|
|
|
|
connect(progress, SIGNAL(appendMessage(QString const &)),
|
|
|
|
this, SLOT(appendText(QString const &)));
|
|
|
|
connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
|
|
|
|
this, SLOT(appendLyXErrText(QString const &)));
|
|
|
|
connect(progress, SIGNAL(appendError(QString const &)),
|
|
|
|
this, SLOT(appendText(QString const &)));
|
2009-12-22 10:33:01 +00:00
|
|
|
connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
|
2009-12-29 15:05:37 +00:00
|
|
|
progress->lyxerrConnect();
|
2009-12-22 10:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-30 14:48:47 +00:00
|
|
|
void GuiProgressView::levelChanged()
|
2009-12-29 15:05:37 +00:00
|
|
|
{
|
2009-12-30 14:48:47 +00:00
|
|
|
int level = Debug::NONE;
|
2010-01-05 22:32:58 +00:00
|
|
|
checked_buttons.clear();
|
|
|
|
Q_FOREACH(LevelButton* button, level_buttons) {
|
2009-12-30 22:17:39 +00:00
|
|
|
if (button->isChecked()) {
|
2010-01-05 22:32:58 +00:00
|
|
|
level |= button->level;
|
|
|
|
checked_buttons << button;
|
2009-12-30 22:17:39 +00:00
|
|
|
}
|
2009-12-30 14:48:47 +00:00
|
|
|
}
|
2010-01-04 17:12:50 +00:00
|
|
|
dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
|
2010-01-05 22:32:58 +00:00
|
|
|
|
2010-01-06 06:49:49 +00:00
|
|
|
toggle_button->setCheckStatusSilent (Qt::PartiallyChecked);
|
2010-01-05 22:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiProgressView::tristateChanged(int state)
|
|
|
|
{
|
|
|
|
if (state != Qt::PartiallyChecked) {
|
|
|
|
Q_FOREACH(LevelButton* button, level_buttons) {
|
2010-01-06 06:49:49 +00:00
|
|
|
button->setCheckStatusSilent(toggle_button->checkState());
|
2010-01-05 22:32:58 +00:00
|
|
|
}
|
|
|
|
int level = (state == Qt::Checked ? Debug::ANY : Debug::NONE);
|
|
|
|
dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
|
|
|
|
} else {
|
|
|
|
Q_FOREACH(LevelButton* button, checked_buttons) {
|
2010-01-06 06:49:49 +00:00
|
|
|
button->setCheckStatusSilent(Qt::Checked);
|
2010-01-05 22:32:58 +00:00
|
|
|
}
|
|
|
|
levelChanged();
|
|
|
|
}
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-22 10:04:30 +00:00
|
|
|
void GuiProgressView::clearText()
|
|
|
|
{
|
2009-12-28 21:40:20 +00:00
|
|
|
if (widget_->autoClearCB->isChecked())
|
|
|
|
widget_->outTE->clear();
|
2009-12-22 10:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-03 16:30:54 +00:00
|
|
|
void GuiProgressView::appendLyXErrText(QString const & text)
|
|
|
|
{
|
|
|
|
widget_->outTE->insertPlainText(text);
|
|
|
|
widget_->outTE->ensureCursorVisible();
|
2010-01-03 16:54:23 +00:00
|
|
|
|
|
|
|
// Give the user a chance to disable debug messages because
|
|
|
|
// showing Debug::ANY messages completely blocks the GUI.
|
|
|
|
// Text is not always send as the whole line, so we must be
|
|
|
|
// careful about eolns.
|
|
|
|
if (text.endsWith("\n"))
|
|
|
|
QApplication::processEvents();
|
2010-01-03 16:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-22 10:04:30 +00:00
|
|
|
void GuiProgressView::appendText(QString const & text)
|
|
|
|
{
|
2010-01-03 17:40:40 +00:00
|
|
|
if (text.isEmpty() || !widget_->sbarCB->isChecked())
|
2009-12-22 10:33:01 +00:00
|
|
|
return;
|
2010-01-03 16:30:54 +00:00
|
|
|
QString str = QTime::currentTime().toString();
|
|
|
|
str += ": " + text;
|
|
|
|
if (!text.endsWith("\n"))
|
|
|
|
str += "\n";
|
2009-12-29 15:05:37 +00:00
|
|
|
|
2010-01-03 16:30:54 +00:00
|
|
|
widget_->outTE->insertPlainText(str);
|
2009-12-28 21:40:14 +00:00
|
|
|
widget_->outTE->ensureCursorVisible();
|
2009-12-22 10:04:30 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 15:05:37 +00:00
|
|
|
|
2009-12-28 21:55:50 +00:00
|
|
|
void GuiProgressView::saveSession() const
|
|
|
|
{
|
|
|
|
Dialog::saveSession();
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue(
|
|
|
|
sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
|
2010-01-03 17:40:40 +00:00
|
|
|
settings.setValue(
|
|
|
|
sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
|
2009-12-28 21:55:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 15:05:37 +00:00
|
|
|
|
2009-12-28 21:55:50 +00:00
|
|
|
void GuiProgressView::restoreSession()
|
|
|
|
{
|
|
|
|
DockView::restoreSession();
|
|
|
|
QSettings settings;
|
|
|
|
widget_->autoClearCB->setChecked(
|
|
|
|
settings.value(sessionKey() + "/autoclear", true).toBool());
|
2010-01-03 17:40:40 +00:00
|
|
|
widget_->sbarCB->setChecked(
|
|
|
|
settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
|
2009-12-28 21:55:50 +00:00
|
|
|
}
|
2009-12-22 10:04:30 +00:00
|
|
|
|
|
|
|
|
2009-12-29 15:05:37 +00:00
|
|
|
void GuiProgressView::showEvent(QShowEvent*)
|
|
|
|
{
|
2010-01-04 17:12:50 +00:00
|
|
|
ProgressInterface::instance()->lyxerrConnect();
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiProgressView::hideEvent(QHideEvent*)
|
|
|
|
{
|
2010-01-04 17:12:50 +00:00
|
|
|
ProgressInterface::instance()->lyxerrDisconnect();
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-22 10:04:30 +00:00
|
|
|
Dialog * createGuiProgressView(GuiView & guiview)
|
|
|
|
{
|
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
|
|
|
|
#else
|
|
|
|
return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2009-12-25 16:52:03 +00:00
|
|
|
#include "moc_GuiProgressView.cpp"
|