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();
67 #if QT_VERSION < 0x040300
68 widget_->scrollArea->setWidget(widget_->scrollAreaWidgetContents);
72 QFont font(guiApp->typewriterFontName());
73 font.setKerning(false);
74 font.setFixedPitch(true);
75 font.setStyleHint(QFont::TypeWriter);
76 widget_->outTE->setFont(font);
77 widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
79 toggle_button = new LevelButton("Toggle ALL messages");
80 toggle_button->level = Debug::ANY;
81 toggle_button->setTristate(true);
82 toggle_button->setCheckState(Qt::PartiallyChecked);
83 widget_->settingsLayout->addWidget(toggle_button);
84 connect(toggle_button, SIGNAL(stateChanged(int)), this, SLOT(tristateChanged(int)));
86 // ignore Debug::NONE and Debug::ANY
87 int const level_count = Debug::levelCount() - 1;
88 for (int i = 1 ; i < level_count; i++) {
89 Debug::Type const level = Debug::value(i);
90 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
92 widget_->settingsLayout->addWidget(box, (i + 3) % 10, (i + 3) / 10);
93 box->setChecked(false);
95 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
97 widget_->settingsLayout->activate();
99 GuiProgress * progress =
100 dynamic_cast<GuiProgress *>(ProgressInterface::instance());
103 connect(progress, SIGNAL(processStarted(QString const &)),
104 this, SLOT(appendText(QString const &)));
105 //connect(progress, SIGNAL(processFinished(QString const &)),
106 // this, SLOT(appendText(QString const &)));
107 connect(progress, SIGNAL(appendMessage(QString const &)),
108 this, SLOT(appendText(QString const &)));
109 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
110 this, SLOT(appendLyXErrText(QString const &)));
111 connect(progress, SIGNAL(appendError(QString const &)),
112 this, SLOT(appendText(QString const &)));
113 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
114 progress->lyxerrConnect();
119 void GuiProgressView::levelChanged()
121 int level = Debug::NONE;
122 checked_buttons.clear();
123 Q_FOREACH(LevelButton* button, level_buttons) {
124 if (button->isChecked()) {
125 level |= button->level;
126 checked_buttons << button;
129 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
131 toggle_button->setCheckStatusSilent (Qt::PartiallyChecked);
135 void GuiProgressView::tristateChanged(int state)
137 if (state != Qt::PartiallyChecked) {
138 Q_FOREACH(LevelButton* button, level_buttons) {
139 button->setCheckStatusSilent(toggle_button->checkState());
141 int level = (state == Qt::Checked ? Debug::ANY : Debug::NONE);
142 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
144 Q_FOREACH(LevelButton* button, checked_buttons) {
145 button->setCheckStatusSilent(Qt::Checked);
152 void GuiProgressView::clearText()
154 if (widget_->autoClearCB->isChecked())
155 widget_->outTE->clear();
159 void GuiProgressView::appendLyXErrText(QString const & text)
161 widget_->outTE->insertPlainText(text);
162 widget_->outTE->ensureCursorVisible();
164 // Give the user a chance to disable debug messages because
165 // showing Debug::ANY messages completely blocks the GUI.
166 // Text is not always send as the whole line, so we must be
167 // careful about eolns.
168 if (text.endsWith("\n"))
169 QApplication::processEvents();
173 void GuiProgressView::appendText(QString const & text)
175 if (text.isEmpty() || !widget_->sbarCB->isChecked())
177 QString str = QTime::currentTime().toString();
179 if (!text.endsWith("\n"))
182 widget_->outTE->insertPlainText(str);
183 widget_->outTE->ensureCursorVisible();
187 void GuiProgressView::saveSession() const
189 Dialog::saveSession();
192 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
194 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
198 void GuiProgressView::restoreSession()
200 DockView::restoreSession();
202 widget_->autoClearCB->setChecked(
203 settings.value(sessionKey() + "/autoclear", true).toBool());
204 widget_->sbarCB->setChecked(
205 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
209 void GuiProgressView::showEvent(QShowEvent*)
211 ProgressInterface::instance()->lyxerrConnect();
215 void GuiProgressView::hideEvent(QHideEvent*)
217 ProgressInterface::instance()->lyxerrDisconnect();
223 Dialog * createGuiProgressView(GuiView & guiview)
226 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
228 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
234 } // namespace frontend
237 #include "moc_GuiProgressView.cpp"