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 (level == Debug::ANY)
79 box->setChecked(levels == level);
81 box->setChecked(levels & level);
84 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
86 widget_->settingsLayout->activate();
88 GuiProgress * progress =
89 dynamic_cast<GuiProgress *>(ProgressInterface::instance());
92 connect(progress, SIGNAL(processStarted(QString const &)),
93 this, SLOT(appendText(QString const &)));
94 //connect(progress, SIGNAL(processFinished(QString const &)),
95 // this, SLOT(appendText(QString const &)));
96 connect(progress, SIGNAL(appendMessage(QString const &)),
97 this, SLOT(appendText(QString const &)));
98 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
99 this, SLOT(appendLyXErrText(QString const &)));
100 connect(progress, SIGNAL(appendError(QString const &)),
101 this, SLOT(appendText(QString const &)));
102 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
103 progress->lyxerrConnect();
108 void GuiProgressView::levelChanged()
110 int level = Debug::NONE;
111 Q_FOREACH(const LevelButton* button, level_buttons) {
112 if (button->isChecked()) {
113 // Debug::NONE overwrites other levels
114 if (button->level == Debug::NONE) {
118 level |= button->level;
122 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
126 void GuiProgressView::clearText()
128 if (widget_->autoClearCB->isChecked())
129 widget_->outTE->clear();
133 void GuiProgressView::appendLyXErrText(QString const & text)
135 widget_->outTE->insertPlainText(text);
136 widget_->outTE->ensureCursorVisible();
138 // Give the user a chance to disable debug messages because
139 // showing Debug::ANY messages completely blocks the GUI.
140 // Text is not always send as the whole line, so we must be
141 // careful about eolns.
142 if (text.endsWith("\n"))
143 QApplication::processEvents();
147 void GuiProgressView::appendText(QString const & text)
149 if (text.isEmpty() || !widget_->sbarCB->isChecked())
151 QString str = QTime::currentTime().toString();
153 if (!text.endsWith("\n"))
156 widget_->outTE->insertPlainText(str);
157 widget_->outTE->ensureCursorVisible();
161 void GuiProgressView::saveSession() const
163 Dialog::saveSession();
166 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
168 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
172 void GuiProgressView::restoreSession()
174 DockView::restoreSession();
176 widget_->autoClearCB->setChecked(
177 settings.value(sessionKey() + "/autoclear", true).toBool());
178 widget_->sbarCB->setChecked(
179 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
183 void GuiProgressView::showEvent(QShowEvent*)
185 ProgressInterface::instance()->lyxerrConnect();
189 void GuiProgressView::hideEvent(QHideEvent*)
191 ProgressInterface::instance()->lyxerrDisconnect();
197 Dialog * createGuiProgressView(GuiView & guiview)
200 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
202 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
208 } // namespace frontend
211 #include "moc_GuiProgressView.cpp"