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 Debug::Type levels = lyxerr.level();
69 // number of initial items in settings tab
71 const int levelCount = Debug::levelCount();
72 for (int i = 0 ; i < levelCount; i++) {
73 const Debug::Type level = Debug::value(i);
74 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
76 widget_->settingsLayout->addWidget(box, (i + shift) % 10, (i + shift) / 10);
77 box->setChecked(false);
79 if ((levels == Debug::ANY) && (levels == level))
80 box->setChecked(true);
82 if ((level != Debug::ANY) && (levels & level))
83 box->setChecked(true);
86 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
90 GuiProgress* progress = dynamic_cast<GuiProgress*>(support::ProgressInterface::instance());
93 connect(progress, SIGNAL(processStarted(QString const &)), this, SLOT(appendText(QString const &)));
94 //connect(progress, SIGNAL(processFinished(QString const &)), this, SLOT(appendText(QString const &)));
95 connect(progress, SIGNAL(appendMessage(QString const &)), this, SLOT(appendText(QString const &)));
96 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)), this, SLOT(appendLyXErrText(QString const &)));
97 connect(progress, SIGNAL(appendError(QString const &)), this, SLOT(appendText(QString const &)));
98 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
99 progress->lyxerrConnect();
104 void GuiProgressView::levelChanged()
106 int level = Debug::NONE;
107 Q_FOREACH(const LevelButton* button, level_buttons) {
108 if (button->isChecked()) {
109 // Debug::NONE overwrites other levels
110 if (button->level == Debug::NONE) {
114 level |= button->level;
118 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<std::string>(level)));
122 void GuiProgressView::clearText()
124 if (widget_->autoClearCB->isChecked())
125 widget_->outTE->clear();
129 void GuiProgressView::appendLyXErrText(QString const & text)
131 widget_->outTE->insertPlainText(text);
132 widget_->outTE->ensureCursorVisible();
134 // Give the user a chance to disable debug messages because
135 // showing Debug::ANY messages completely blocks the GUI.
136 // Text is not always send as the whole line, so we must be
137 // careful about eolns.
138 if (text.endsWith("\n"))
139 QApplication::processEvents();
143 void GuiProgressView::appendText(QString const & text)
145 if (text.isEmpty() || !widget_->sbarCB->isChecked())
147 QString str = QTime::currentTime().toString();
149 if (!text.endsWith("\n"))
152 widget_->outTE->insertPlainText(str);
153 widget_->outTE->ensureCursorVisible();
157 void GuiProgressView::saveSession() const
159 Dialog::saveSession();
162 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
164 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
168 void GuiProgressView::restoreSession()
170 DockView::restoreSession();
172 widget_->autoClearCB->setChecked(
173 settings.value(sessionKey() + "/autoclear", true).toBool());
174 widget_->sbarCB->setChecked(
175 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
179 void GuiProgressView::showEvent(QShowEvent*)
181 support::ProgressInterface::instance()->lyxerrConnect();
185 void GuiProgressView::hideEvent(QHideEvent*)
187 support::ProgressInterface::instance()->lyxerrDisconnect();
193 Dialog * createGuiProgressView(GuiView & guiview)
196 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
198 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
204 } // namespace frontend
207 #include "moc_GuiProgressView.cpp"