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"
31 using namespace lyx::support;
37 struct LevelButton : QCheckBox
39 LevelButton(const QString& name) : QCheckBox(name) {}
44 ProgressViewWidget::ProgressViewWidget()
51 GuiProgressView::~GuiProgressView()
57 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
58 Qt::WindowFlags flags) : DockView(parent, "progress", "Debug/Progress window", area, flags)
60 widget_ = new ProgressViewWidget();
63 QFont font(guiApp->typewriterFontName());
64 font.setKerning(false);
65 font.setFixedPitch(true);
66 font.setStyleHint(QFont::TypeWriter);
67 widget_->outTE->setFont(font);
68 widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
70 toggle_button = new LevelButton("Toggle ALL messages");
71 toggle_button->level = Debug::ANY;
72 toggle_button->setTristate(true);
73 toggle_button->setCheckState(Qt::PartiallyChecked);
74 widget_->settingsLayout->addWidget(toggle_button);
75 connect(toggle_button, SIGNAL(stateChanged(int)), this, SLOT(tristateChanged(int)));
77 // ignore Debug::NONE and Debug::ANY
78 int const level_count = Debug::levelCount() - 1;
79 for (int i = 1 ; i < level_count; i++) {
80 Debug::Type const level = Debug::value(i);
81 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
83 widget_->settingsLayout->addWidget(box, (i + 3) % 10, (i + 3) / 10);
84 box->setChecked(false);
86 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
88 widget_->settingsLayout->activate();
90 GuiProgress * progress =
91 dynamic_cast<GuiProgress *>(ProgressInterface::instance());
94 connect(progress, SIGNAL(processStarted(QString const &)),
95 this, SLOT(appendText(QString const &)));
96 //connect(progress, SIGNAL(processFinished(QString const &)),
97 // this, SLOT(appendText(QString const &)));
98 connect(progress, SIGNAL(appendMessage(QString const &)),
99 this, SLOT(appendText(QString const &)));
100 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
101 this, SLOT(appendLyXErrText(QString const &)));
102 connect(progress, SIGNAL(appendError(QString const &)),
103 this, SLOT(appendText(QString const &)));
104 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
105 progress->lyxerrConnect();
110 void GuiProgressView::levelChanged()
112 int level = Debug::NONE;
113 checked_buttons.clear();
114 Q_FOREACH(LevelButton* button, level_buttons) {
115 if (button->isChecked()) {
116 level |= button->level;
117 checked_buttons << button;
120 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
122 toggle_button->blockSignals(true);
123 toggle_button->setCheckState (Qt::PartiallyChecked);
124 toggle_button->blockSignals(false);
128 void GuiProgressView::tristateChanged(int state)
130 if (state != Qt::PartiallyChecked) {
131 Q_FOREACH(LevelButton* button, level_buttons) {
132 button->blockSignals(true);
133 button->setChecked(toggle_button->checkState());
134 button->blockSignals(false);
136 int level = (state == Qt::Checked ? Debug::ANY : Debug::NONE);
137 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
139 Q_FOREACH(LevelButton* button, checked_buttons) {
140 button->blockSignals(true);
141 button->setChecked(true);
142 button->blockSignals(false);
149 void GuiProgressView::clearText()
151 if (widget_->autoClearCB->isChecked())
152 widget_->outTE->clear();
156 void GuiProgressView::appendLyXErrText(QString const & text)
158 widget_->outTE->insertPlainText(text);
159 widget_->outTE->ensureCursorVisible();
161 // Give the user a chance to disable debug messages because
162 // showing Debug::ANY messages completely blocks the GUI.
163 // Text is not always send as the whole line, so we must be
164 // careful about eolns.
165 if (text.endsWith("\n"))
166 QApplication::processEvents();
170 void GuiProgressView::appendText(QString const & text)
172 if (text.isEmpty() || !widget_->sbarCB->isChecked())
174 QString str = QTime::currentTime().toString();
176 if (!text.endsWith("\n"))
179 widget_->outTE->insertPlainText(str);
180 widget_->outTE->ensureCursorVisible();
184 void GuiProgressView::saveSession() const
186 Dialog::saveSession();
189 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
191 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
195 void GuiProgressView::restoreSession()
197 DockView::restoreSession();
199 widget_->autoClearCB->setChecked(
200 settings.value(sessionKey() + "/autoclear", true).toBool());
201 widget_->sbarCB->setChecked(
202 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
206 void GuiProgressView::showEvent(QShowEvent*)
208 ProgressInterface::instance()->lyxerrConnect();
212 void GuiProgressView::hideEvent(QHideEvent*)
214 ProgressInterface::instance()->lyxerrDisconnect();
220 Dialog * createGuiProgressView(GuiView & guiview)
223 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
225 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
231 } // namespace frontend
234 #include "moc_GuiProgressView.cpp"