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) {}
42 void setCheckStatusSilent(Qt::CheckState state) {
50 ProgressViewWidget::ProgressViewWidget()
57 GuiProgressView::~GuiProgressView()
63 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
64 Qt::WindowFlags flags) : DockView(parent, "progress", "Debug/Progress window", area, flags)
66 widget_ = new ProgressViewWidget();
69 QFont font(guiApp->typewriterFontName());
70 font.setKerning(false);
71 font.setFixedPitch(true);
72 font.setStyleHint(QFont::TypeWriter);
73 widget_->outTE->setFont(font);
74 widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
76 toggle_button = new LevelButton("Toggle ALL messages");
77 toggle_button->level = Debug::ANY;
78 toggle_button->setTristate(true);
79 toggle_button->setCheckState(Qt::PartiallyChecked);
80 widget_->settingsLayout->addWidget(toggle_button);
81 connect(toggle_button, SIGNAL(stateChanged(int)), this, SLOT(tristateChanged(int)));
83 // ignore Debug::NONE and Debug::ANY
84 int const level_count = Debug::levelCount() - 1;
85 for (int i = 1 ; i < level_count; i++) {
86 Debug::Type const level = Debug::value(i);
87 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
89 widget_->settingsLayout->addWidget(box, (i + 3) % 10, (i + 3) / 10);
90 box->setChecked(false);
92 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
94 widget_->settingsLayout->activate();
96 GuiProgress * progress =
97 dynamic_cast<GuiProgress *>(ProgressInterface::instance());
100 connect(progress, SIGNAL(processStarted(QString const &)),
101 this, SLOT(appendText(QString const &)));
102 //connect(progress, SIGNAL(processFinished(QString const &)),
103 // this, SLOT(appendText(QString const &)));
104 connect(progress, SIGNAL(appendMessage(QString const &)),
105 this, SLOT(appendText(QString const &)));
106 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
107 this, SLOT(appendLyXErrText(QString const &)));
108 connect(progress, SIGNAL(appendError(QString const &)),
109 this, SLOT(appendText(QString const &)));
110 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
111 progress->lyxerrConnect();
116 void GuiProgressView::levelChanged()
118 int level = Debug::NONE;
119 checked_buttons.clear();
120 Q_FOREACH(LevelButton* button, level_buttons) {
121 if (button->isChecked()) {
122 level |= button->level;
123 checked_buttons << button;
126 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
128 toggle_button->setCheckStatusSilent (Qt::PartiallyChecked);
132 void GuiProgressView::tristateChanged(int state)
134 if (state != Qt::PartiallyChecked) {
135 Q_FOREACH(LevelButton* button, level_buttons) {
136 button->setCheckStatusSilent(toggle_button->checkState());
138 int level = (state == Qt::Checked ? Debug::ANY : Debug::NONE);
139 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
141 Q_FOREACH(LevelButton* button, checked_buttons) {
142 button->setCheckStatusSilent(Qt::Checked);
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"