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"
34 struct LevelButton : QCheckBox
36 LevelButton(const QString& name) : QCheckBox(name) {}
41 ProgressViewWidget::ProgressViewWidget()
48 GuiProgressView::~GuiProgressView()
54 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
55 Qt::WindowFlags flags) : DockView(parent, "progress", "Debug/Progress window", area, flags)
57 widget_ = new ProgressViewWidget();
60 QFont font(guiApp->typewriterFontName());
61 font.setKerning(false);
62 font.setFixedPitch(true);
63 font.setStyleHint(QFont::TypeWriter);
64 widget_->outTE->setFont(font);
65 widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
68 // number of initial items in settings tab
70 const int levelCount = Debug::levelCount();
71 for (int i = 0 ; i < levelCount; i++) {
72 const Debug::Type level = Debug::value(i);
73 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
75 widget_->settingsLayout->addWidget(box, (i + shift) % 10, (i + shift) / 10);
77 box->setChecked(false);
79 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
83 GuiProgress* progress = dynamic_cast<GuiProgress*>(support::ProgressInterface::instance());
86 connect(progress, SIGNAL(processStarted(QString const &)), this, SLOT(appendText(QString const &)));
87 //connect(progress, SIGNAL(processFinished(QString const &)), this, SLOT(appendText(QString const &)));
88 connect(progress, SIGNAL(appendMessage(QString const &)), this, SLOT(appendText(QString const &)));
89 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)), this, SLOT(appendLyXErrText(QString const &)));
90 connect(progress, SIGNAL(appendError(QString const &)), this, SLOT(appendText(QString const &)));
91 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
92 progress->lyxerrConnect();
97 void GuiProgressView::levelChanged()
99 int level = Debug::NONE;
100 Q_FOREACH(const LevelButton* button, level_buttons) {
101 if (button->isChecked()) {
102 // Debug::NONE overwrites other levels
103 if (button->level == Debug::NONE) {
107 level |= button->level;
111 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<std::string>(level)));
115 void GuiProgressView::clearText()
117 if (widget_->autoClearCB->isChecked())
118 widget_->outTE->clear();
122 void GuiProgressView::appendLyXErrText(QString const & text)
124 widget_->outTE->insertPlainText(text);
125 widget_->outTE->ensureCursorVisible();
127 // Give the user a chance to disable debug messages because
128 // showing Debug::ANY messages completely blocks the GUI.
129 // Text is not always send as the whole line, so we must be
130 // careful about eolns.
131 if (text.endsWith("\n"))
132 QApplication::processEvents();
136 void GuiProgressView::appendText(QString const & text)
140 QString str = QTime::currentTime().toString();
142 if (!text.endsWith("\n"))
145 widget_->outTE->insertPlainText(str);
146 widget_->outTE->ensureCursorVisible();
150 void GuiProgressView::saveSession() const
152 Dialog::saveSession();
155 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
159 void GuiProgressView::restoreSession()
161 DockView::restoreSession();
163 widget_->autoClearCB->setChecked(
164 settings.value(sessionKey() + "/autoclear", true).toBool());
168 void GuiProgressView::showEvent(QShowEvent*)
170 support::ProgressInterface::instance()->lyxerrConnect();
174 void GuiProgressView::hideEvent(QHideEvent*)
176 support::ProgressInterface::instance()->lyxerrDisconnect();
182 Dialog * createGuiProgressView(GuiView & guiview)
185 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
187 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
193 } // namespace frontend
196 #include "moc_GuiProgressView.cpp"