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);
67 const int levelCount = Debug::levelCount();
68 for (int i = 0; i < levelCount; i++) {
69 const Debug::Type level = Debug::value(i);
70 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
72 widget_->settingsLayout->addWidget(box);
74 box->setChecked(false);
76 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
80 GuiProgress* progress = dynamic_cast<GuiProgress*>(support::ProgressInterface::instance());
83 connect(progress, SIGNAL(processStarted(QString const &)), this, SLOT(appendText(QString const &)));
84 //connect(progress, SIGNAL(processFinished(QString const &)), this, SLOT(appendText(QString const &)));
85 connect(progress, SIGNAL(appendMessage(QString const &)), this, SLOT(appendText(QString const &)));
86 connect(progress, SIGNAL(appendError(QString const &)), this, SLOT(appendText(QString const &)));
87 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
88 progress->lyxerrConnect();
93 void GuiProgressView::levelChanged()
95 int level = Debug::NONE;
96 Q_FOREACH(const LevelButton* button, level_buttons) {
97 if (button->isChecked()) {
98 // Debug::NONE overwrites other levels
99 if (button->level == Debug::NONE) {
103 level |= button->level;
107 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<std::string>(level)));
111 void GuiProgressView::clearText()
113 if (widget_->autoClearCB->isChecked())
114 widget_->outTE->clear();
118 void GuiProgressView::appendText(QString const & text)
122 QString time = QTime::currentTime().toString();
123 if (text.endsWith("\n"))
124 widget_->outTE->insertPlainText(time + ": " + text);
126 widget_->outTE->insertPlainText(text);
128 widget_->outTE->ensureCursorVisible();
132 void GuiProgressView::saveSession() const
134 Dialog::saveSession();
137 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
141 void GuiProgressView::restoreSession()
143 DockView::restoreSession();
145 widget_->autoClearCB->setChecked(
146 settings.value(sessionKey() + "/autoclear", true).toBool());
150 void GuiProgressView::showEvent(QShowEvent*)
152 support::ProgressInterface::instance()->lyxerrConnect();
156 void GuiProgressView::hideEvent(QHideEvent*)
158 support::ProgressInterface::instance()->lyxerrDisconnect();
164 Dialog * createGuiProgressView(GuiView & guiview)
167 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
169 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
175 } // namespace frontend
178 #include "moc_GuiProgressView.cpp"