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 #if (QT_VERSION >= 0x040500)
70 QFont font(guiApp->typewriterFontName());
71 font.setKerning(false);
72 font.setFixedPitch(true);
73 font.setStyleHint(QFont::TypeWriter);
74 widget_->outTE->setFont(font);
75 widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
77 toggle_button = new LevelButton("Toggle ALL messages");
78 toggle_button->level = Debug::ANY;
79 toggle_button->setTristate(true);
80 toggle_button->setCheckState(Qt::PartiallyChecked);
81 widget_->settingsLayout->addWidget(toggle_button);
82 connect(toggle_button, SIGNAL(stateChanged(int)), this, SLOT(tristateChanged(int)));
84 // ignore Debug::NONE and Debug::ANY
85 int const level_count = Debug::levelCount() - 1;
86 for (int i = 1 ; i < level_count; i++) {
87 Debug::Type const level = Debug::value(i);
88 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
90 widget_->settingsLayout->addWidget(box, (i + 3) % 10, (i + 3) / 10);
91 box->setChecked(false);
93 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
95 widget_->settingsLayout->activate();
98 GuiProgress * progress =
99 dynamic_cast<GuiProgress *>(ProgressInterface::instance());
102 connect(progress, SIGNAL(processStarted(QString const &)),
103 this, SLOT(appendText(QString const &)));
104 //connect(progress, SIGNAL(processFinished(QString const &)),
105 // this, SLOT(appendText(QString const &)));
106 connect(progress, SIGNAL(appendMessage(QString const &)),
107 this, SLOT(appendText(QString const &)));
108 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
109 this, SLOT(appendLyXErrText(QString const &)));
110 connect(progress, SIGNAL(appendError(QString const &)),
111 this, SLOT(appendText(QString const &)));
112 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
113 progress->lyxerrConnect();
118 void GuiProgressView::levelChanged()
120 int level = Debug::NONE;
121 checked_buttons.clear();
122 Q_FOREACH(LevelButton* button, level_buttons) {
123 if (button->isChecked()) {
124 level |= button->level;
125 checked_buttons << button;
128 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
130 toggle_button->setCheckStatusSilent (Qt::PartiallyChecked);
134 void GuiProgressView::tristateChanged(int state)
136 if (state != Qt::PartiallyChecked) {
137 Q_FOREACH(LevelButton* button, level_buttons) {
138 button->setCheckStatusSilent(toggle_button->checkState());
140 int level = (state == Qt::Checked ? Debug::ANY : Debug::NONE);
141 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
143 Q_FOREACH(LevelButton* button, checked_buttons) {
144 button->setCheckStatusSilent(Qt::Checked);
151 void GuiProgressView::clearText()
153 if (widget_->autoClearCB->isChecked())
154 widget_->outTE->clear();
158 void GuiProgressView::appendLyXErrText(QString const & text)
160 widget_->outTE->insertPlainText(text);
161 widget_->outTE->ensureCursorVisible();
163 // Give the user a chance to disable debug messages because
164 // showing Debug::ANY messages completely blocks the GUI.
165 // Text is not always send as the whole line, so we must be
166 // careful about eolns.
167 if (text.endsWith("\n"))
168 QApplication::processEvents();
172 void GuiProgressView::appendText(QString const & text)
174 if (text.isEmpty() || !widget_->sbarCB->isChecked())
176 QString str = QTime::currentTime().toString();
178 if (!text.endsWith("\n"))
181 widget_->outTE->insertPlainText(str);
182 widget_->outTE->ensureCursorVisible();
186 void GuiProgressView::saveSession() const
188 Dialog::saveSession();
191 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
193 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
197 void GuiProgressView::restoreSession()
199 DockView::restoreSession();
201 widget_->autoClearCB->setChecked(
202 settings.value(sessionKey() + "/autoclear", true).toBool());
203 widget_->sbarCB->setChecked(
204 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
208 void GuiProgressView::showEvent(QShowEvent*)
210 #if (QT_VERSION >= 0x040500)
211 ProgressInterface::instance()->lyxerrConnect();
218 void GuiProgressView::hideEvent(QHideEvent*)
220 ProgressInterface::instance()->lyxerrDisconnect();
226 Dialog * createGuiProgressView(GuiView & guiview)
229 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
231 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
237 } // namespace frontend
240 #include "moc_GuiProgressView.cpp"