X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiProgressView.cpp;h=004c70e86a69b1348dd07b434bd23c2775caa846;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=d1d1de3391f39fdd073c27e351796a25d9b32d97;hpb=12efe108db4fa722c480bee7cb8f65e8303c6901;p=lyx.git diff --git a/src/frontends/qt4/GuiProgressView.cpp b/src/frontends/qt4/GuiProgressView.cpp index d1d1de3391..004c70e86a 100644 --- a/src/frontends/qt4/GuiProgressView.cpp +++ b/src/frontends/qt4/GuiProgressView.cpp @@ -6,6 +6,7 @@ * * \author Peter Kümmel * \author Pavel Sanda + * \author Jürgen Spitzmüller * * Full author contact details are available in file CREDITS. */ @@ -13,33 +14,30 @@ #include #include "GuiProgressView.h" -#include "GuiApplication.h" +#include "GuiApplication.h" #include "qt_helpers.h" +#include "FuncRequest.h" + +#include "support/convert.h" #include "support/debug.h" +#include +#include #include #include -#include -#include -#include + +using namespace std; +using namespace lyx::support; namespace lyx { namespace frontend { -struct LevelButton : QRadioButton -{ - LevelButton(const QString& name) : QRadioButton(name) {} - Debug::Type level; -}; - - ProgressViewWidget::ProgressViewWidget() { setupUi(this); - } @@ -50,9 +48,14 @@ GuiProgressView::~GuiProgressView() GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area, - Qt::WindowFlags flags) : DockView(parent, "progress", "Debug/Progress window", area, flags) + Qt::WindowFlags flags) + : DockView(parent, "progress", qt_("Progress/Debug Messages"), area, flags) { widget_ = new ProgressViewWidget(); + widget_->setMinimumHeight(150); + widget_->debugMessagesTW->setSizePolicy(QSizePolicy::Ignored, + QSizePolicy::Expanding); + widget_->adjustSize(); setWidget(widget_); QFont font(guiApp->typewriterFontName()); @@ -60,37 +63,96 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area, font.setFixedPitch(true); font.setStyleHint(QFont::TypeWriter); widget_->outTE->setFont(font); - - QButtonGroup* button_group = new QButtonGroup(this); - const std::vector levels = Debug::levels(); - for (unsigned int i = 0; i < levels.size(); i++) { - LevelButton * box = new LevelButton(toqstr(Debug::description(levels[i]))); - box->level = levels[i]; - widget_->settingsLayout->addWidget(box); - button_group->addButton(box); + widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7); + + connect(widget_->debugNoneRB, SIGNAL(clicked()), + this, SLOT(debugSelectionChanged())); + connect(widget_->debugSelectedRB, SIGNAL(clicked()), + this, SLOT(debugSelectionChanged())); + connect(widget_->debugAnyRB, SIGNAL(clicked()), + this, SLOT(debugSelectionChanged())); + widget_->debugMessagesTW->setEnabled(false); + widget_->debugNoneRB->setChecked(true); + + // ignore Debug::NONE and Debug::ANY + int const level_count = Debug::levelCount() - 1; + QTreeWidgetItem * item = 0; + widget_->debugMessagesTW->setColumnCount(2); + widget_->debugMessagesTW->headerItem()->setText(0, qt_("Debug Level")); + widget_->debugMessagesTW->headerItem()->setText(1, qt_("Set")); + for (int i = 1 ; i < level_count; i++) { + item = new QTreeWidgetItem(widget_->debugMessagesTW); + Debug::Type const level = Debug::value(i); + item->setText(0, qt_(Debug::description(level))); + item->setData(0, Qt::UserRole, int(level)); + item->setText(1, qt_("No")); } - connect(button_group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(levelChanged(QAbstractButton*))); - // TODO settings - button_group->buttons().front()->setChecked(true); - - GuiProgress* progress = dynamic_cast(support::ProgressInterface::instance()); + widget_->debugMessagesTW->resizeColumnToContents(0); + widget_->debugMessagesTW->resizeColumnToContents(1); + connect(widget_->debugMessagesTW, + SIGNAL(itemActivated(QTreeWidgetItem *, int)), + this, SLOT(debugMessageActivated(QTreeWidgetItem *, int))); + + GuiProgress * progress = + dynamic_cast(ProgressInterface::instance()); if (progress) { - 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(appendError(QString const &)), this, SLOT(appendText(QString const &))); + 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 &))); connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText())); progress->lyxerrConnect(); } } -void GuiProgressView::levelChanged(QAbstractButton* b) +void GuiProgressView::debugMessageActivated(QTreeWidgetItem * item, int) { - LevelButton* lb = dynamic_cast(b); - if (lb) - lyxerr.level(lb->level); + if (item == 0) + return; + + QString const no = qt_("No"); + QString const yes = qt_("Yes"); + + bool selected = (item->text(1) == yes); + item->setText(1, selected ? no : yes); + + levelChanged(); +} + + +void GuiProgressView::levelChanged() +{ + int level = Debug::NONE; + QTreeWidgetItemIterator it(widget_->debugMessagesTW); + while (*it) { + if ((*it)->text(1) == qt_("Yes")) + level |= (*it)->data(0, Qt::UserRole).toInt(); + ++it; + } + dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert(level))); +} + + +void GuiProgressView::debugSelectionChanged() +{ + int level = Debug::NONE; + if (widget_->debugAnyRB->isChecked()) + level = Debug::ANY; + else if (widget_->debugSelectedRB->isChecked()) { + widget_->debugMessagesTW->setEnabled(true); + levelChanged(); + return; + } + widget_->debugMessagesTW->setEnabled(false); + dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert(level))); } @@ -101,16 +163,34 @@ void GuiProgressView::clearText() } +void GuiProgressView::appendLyXErrText(QString const & text) +{ + widget_->outTE->moveCursor(QTextCursor::End); + widget_->outTE->insertPlainText(text); + widget_->outTE->ensureCursorVisible(); + + // 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. + // WARNING: processing events could cause crashes! + // TODO: find a better solution + if (text.endsWith("\n")) + QApplication::processEvents(); +} + + void GuiProgressView::appendText(QString const & text) { - if (text.isEmpty()) + if (text.isEmpty() || !widget_->sbarCB->isChecked()) return; - QString time = QTime::currentTime().toString(); - if (text.endsWith("\n")) - widget_->outTE->insertPlainText(time + ": " + text); - else - widget_->outTE->insertPlainText(text); + QString str = QTime::currentTime().toString(); + str += ": " + text; + if (!text.endsWith("\n")) + str += "\n"; + widget_->outTE->moveCursor(QTextCursor::End); + widget_->outTE->insertPlainText(str); widget_->outTE->ensureCursorVisible(); } @@ -121,6 +201,8 @@ void GuiProgressView::saveSession() const QSettings settings; settings.setValue( sessionKey() + "/autoclear", widget_->autoClearCB->isChecked()); + settings.setValue( + sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked()); } @@ -130,23 +212,23 @@ void GuiProgressView::restoreSession() QSettings settings; widget_->autoClearCB->setChecked( settings.value(sessionKey() + "/autoclear", true).toBool()); + widget_->sbarCB->setChecked( + settings.value(sessionKey() + "/statusbarmsgs", true).toBool()); } void GuiProgressView::showEvent(QShowEvent*) { - support::ProgressInterface::instance()->lyxerrConnect(); + ProgressInterface::instance()->lyxerrConnect(); } void GuiProgressView::hideEvent(QHideEvent*) { - support::ProgressInterface::instance()->lyxerrDisconnect(); + ProgressInterface::instance()->lyxerrDisconnect(); } - - Dialog * createGuiProgressView(GuiView & guiview) { #ifdef Q_WS_MACX