3 * \file GuiProgressView.cpp
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
15 #include "GuiProgressView.h"
16 #include "GuiApplication.h"
18 #include "qt_helpers.h"
19 #include "FuncRequest.h"
21 #include "support/debug.h"
22 #include "support/convert.h"
30 using namespace lyx::support;
36 struct LevelButton : QCheckBox
38 LevelButton(const QString& name) : QCheckBox(name) {}
43 ProgressViewWidget::ProgressViewWidget()
50 GuiProgressView::~GuiProgressView()
56 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
57 Qt::WindowFlags flags) : DockView(parent, "progress", "Debug/Progress window", area, flags)
59 widget_ = new ProgressViewWidget();
62 QFont font(guiApp->typewriterFontName());
63 font.setKerning(false);
64 font.setFixedPitch(true);
65 font.setStyleHint(QFont::TypeWriter);
66 widget_->outTE->setFont(font);
67 widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
69 Debug::Type const levels = lyxerr.level();
70 // number of initial items in settings tab
71 int const level_count = Debug::levelCount();
72 for (int i = 0 ; i < level_count; i++) {
73 Debug::Type const level = Debug::value(i);
74 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
76 widget_->settingsLayout->addWidget(box, (i + 3) % 10, (i + 3) / 10);
78 if ((levels == Debug::ANY) && (levels == level))
79 box->setChecked(true);
81 if ((level != Debug::ANY) && (levels & level))
82 box->setChecked(true);
85 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
89 GuiProgress * progress =
90 dynamic_cast<GuiProgress *>(ProgressInterface::instance());
93 connect(progress, SIGNAL(processStarted(QString const &)),
94 this, SLOT(appendText(QString const &)));
95 //connect(progress, SIGNAL(processFinished(QString const &)),
96 // this, SLOT(appendText(QString const &)));
97 connect(progress, SIGNAL(appendMessage(QString const &)),
98 this, SLOT(appendText(QString const &)));
99 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
100 this, SLOT(appendLyXErrText(QString const &)));
101 connect(progress, SIGNAL(appendError(QString const &)),
102 this, SLOT(appendText(QString const &)));
103 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
104 progress->lyxerrConnect();
109 void GuiProgressView::levelChanged()
111 int level = Debug::NONE;
112 Q_FOREACH(const LevelButton* button, level_buttons) {
113 if (button->isChecked()) {
114 // Debug::NONE overwrites other levels
115 if (button->level == Debug::NONE) {
119 level |= button->level;
123 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
127 void GuiProgressView::clearText()
129 if (widget_->autoClearCB->isChecked())
130 widget_->outTE->clear();
134 void GuiProgressView::appendLyXErrText(QString const & text)
136 widget_->outTE->insertPlainText(text);
137 widget_->outTE->ensureCursorVisible();
139 // Give the user a chance to disable debug messages because
140 // showing Debug::ANY messages completely blocks the GUI.
141 // Text is not always send as the whole line, so we must be
142 // careful about eolns.
143 if (text.endsWith("\n"))
144 QApplication::processEvents();
148 void GuiProgressView::appendText(QString const & text)
150 if (text.isEmpty() || !widget_->sbarCB->isChecked())
152 QString str = QTime::currentTime().toString();
154 if (!text.endsWith("\n"))
157 widget_->outTE->insertPlainText(str);
158 widget_->outTE->ensureCursorVisible();
162 void GuiProgressView::saveSession() const
164 Dialog::saveSession();
167 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
169 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
173 void GuiProgressView::restoreSession()
175 DockView::restoreSession();
177 widget_->autoClearCB->setChecked(
178 settings.value(sessionKey() + "/autoclear", true).toBool());
179 widget_->sbarCB->setChecked(
180 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
184 void GuiProgressView::showEvent(QShowEvent*)
186 ProgressInterface::instance()->lyxerrConnect();
190 void GuiProgressView::hideEvent(QHideEvent*)
192 ProgressInterface::instance()->lyxerrDisconnect();
198 Dialog * createGuiProgressView(GuiView & guiview)
201 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
203 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
209 } // namespace frontend
212 #include "moc_GuiProgressView.cpp"