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"
17 #include "GuiApplication.h"
18 #include "qt_helpers.h"
20 #include "FuncRequest.h"
22 #include "support/convert.h"
23 #include "support/debug.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 < 0x040400
68 widget_->scrollArea->setWidget(widget_->scrollAreaWidgetContents);
70 widget_->setMinimumHeight(150);
71 widget_->adjustSize();
74 QFont font(guiApp->typewriterFontName());
75 font.setKerning(false);
76 font.setFixedPitch(true);
77 font.setStyleHint(QFont::TypeWriter);
78 widget_->outTE->setFont(font);
79 widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
81 toggle_button = new LevelButton("Toggle ALL messages");
82 toggle_button->level = Debug::ANY;
83 toggle_button->setTristate(true);
84 toggle_button->setCheckState(Qt::PartiallyChecked);
85 widget_->settingsLayout->addWidget(toggle_button);
86 connect(toggle_button, SIGNAL(stateChanged(int)), this, SLOT(tristateChanged(int)));
88 // ignore Debug::NONE and Debug::ANY
89 int const level_count = Debug::levelCount() - 1;
90 for (int i = 1 ; i < level_count; i++) {
91 Debug::Type const level = Debug::value(i);
92 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
94 widget_->settingsLayout->addWidget(box, (i + 3) % 10, (i + 3) / 10);
95 box->setChecked(false);
97 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
99 widget_->settingsLayout->activate();
101 GuiProgress * progress =
102 dynamic_cast<GuiProgress *>(ProgressInterface::instance());
105 connect(progress, SIGNAL(processStarted(QString const &)),
106 this, SLOT(appendText(QString const &)));
107 //connect(progress, SIGNAL(processFinished(QString const &)),
108 // this, SLOT(appendText(QString const &)));
109 connect(progress, SIGNAL(appendMessage(QString const &)),
110 this, SLOT(appendText(QString const &)));
111 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
112 this, SLOT(appendLyXErrText(QString const &)));
113 connect(progress, SIGNAL(appendError(QString const &)),
114 this, SLOT(appendText(QString const &)));
115 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
116 progress->lyxerrConnect();
121 void GuiProgressView::levelChanged()
123 int level = Debug::NONE;
124 checked_buttons.clear();
125 Q_FOREACH(LevelButton* button, level_buttons) {
126 if (button->isChecked()) {
127 level |= button->level;
128 checked_buttons << button;
131 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
133 toggle_button->setCheckStatusSilent (Qt::PartiallyChecked);
137 void GuiProgressView::tristateChanged(int state)
139 if (state != Qt::PartiallyChecked) {
140 Q_FOREACH(LevelButton* button, level_buttons) {
141 button->setCheckStatusSilent(toggle_button->checkState());
143 int level = (state == Qt::Checked ? Debug::ANY : Debug::NONE);
144 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
146 Q_FOREACH(LevelButton* button, checked_buttons) {
147 button->setCheckStatusSilent(Qt::Checked);
154 void GuiProgressView::clearText()
156 if (widget_->autoClearCB->isChecked())
157 widget_->outTE->clear();
161 void GuiProgressView::appendLyXErrText(QString const & text)
163 widget_->outTE->insertPlainText(text);
164 widget_->outTE->ensureCursorVisible();
166 // Give the user a chance to disable debug messages because
167 // showing Debug::ANY messages completely blocks the GUI.
168 // Text is not always send as the whole line, so we must be
169 // careful about eolns.
170 if (text.endsWith("\n"))
171 QApplication::processEvents();
175 void GuiProgressView::appendText(QString const & text)
177 if (text.isEmpty() || !widget_->sbarCB->isChecked())
179 QString str = QTime::currentTime().toString();
181 if (!text.endsWith("\n"))
184 widget_->outTE->insertPlainText(str);
185 widget_->outTE->ensureCursorVisible();
189 void GuiProgressView::saveSession() const
191 Dialog::saveSession();
194 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
196 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
200 void GuiProgressView::restoreSession()
202 DockView::restoreSession();
204 widget_->autoClearCB->setChecked(
205 settings.value(sessionKey() + "/autoclear", true).toBool());
206 widget_->sbarCB->setChecked(
207 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
211 void GuiProgressView::showEvent(QShowEvent*)
213 ProgressInterface::instance()->lyxerrConnect();
217 void GuiProgressView::hideEvent(QHideEvent*)
219 ProgressInterface::instance()->lyxerrDisconnect();
225 Dialog * createGuiProgressView(GuiView & guiview)
228 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
230 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
236 } // namespace frontend
239 #include "moc_GuiProgressView.cpp"