3 * \file GuiProgressView.cpp
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * \author Jürgen Spitzmüller
11 * Full author contact details are available in file CREDITS.
16 #include "GuiProgressView.h"
18 #include "GuiApplication.h"
19 #include "qt_helpers.h"
21 #include "FuncRequest.h"
23 #include "support/convert.h"
24 #include "support/debug.h"
32 using namespace lyx::support;
38 ProgressViewWidget::ProgressViewWidget()
44 GuiProgressView::~GuiProgressView()
50 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
51 Qt::WindowFlags flags)
52 : DockView(parent, "progress", qt_("Progress/Debug Messages"), area, flags)
54 widget_ = new ProgressViewWidget();
55 widget_->setMinimumHeight(150);
56 widget_->adjustSize();
59 QFont font(guiApp->typewriterFontName());
60 font.setKerning(false);
61 font.setFixedPitch(true);
62 font.setStyleHint(QFont::TypeWriter);
63 widget_->outTE->setFont(font);
64 widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
66 connect(widget_->debugNoneRB, SIGNAL(clicked()),
67 this, SLOT(debugSelectionChanged()));
68 connect(widget_->debugSelectedRB, SIGNAL(clicked()),
69 this, SLOT(debugSelectionChanged()));
70 connect(widget_->debugAnyRB, SIGNAL(clicked()),
71 this, SLOT(debugSelectionChanged()));
72 widget_->debugMessagesTW->setEnabled(false);
73 widget_->debugNoneRB->setChecked(true);
75 // ignore Debug::NONE and Debug::ANY
76 int const level_count = Debug::levelCount() - 1;
77 QTreeWidgetItem * item = 0;
78 widget_->debugMessagesTW->setColumnCount(2);
79 widget_->debugMessagesTW->headerItem()->setText(0, qt_("Debug Level"));
80 widget_->debugMessagesTW->headerItem()->setText(1, qt_("Set"));
81 for (int i = 1 ; i < level_count; i++) {
82 item = new QTreeWidgetItem(widget_->debugMessagesTW);
83 Debug::Type const level = Debug::value(i);
84 item->setText(0, qt_(Debug::description(level)));
85 item->setData(0, Qt::UserRole, int(level));
86 item->setText(1, qt_("No"));
88 widget_->debugMessagesTW->resizeColumnToContents(0);
89 widget_->debugMessagesTW->resizeColumnToContents(1);
90 connect(widget_->debugMessagesTW,
91 SIGNAL(itemActivated(QTreeWidgetItem *, int)),
92 this, SLOT(debugMessageActivated(QTreeWidgetItem *, int)));
94 GuiProgress * progress =
95 dynamic_cast<GuiProgress *>(ProgressInterface::instance());
98 connect(progress, SIGNAL(processStarted(QString const &)),
99 this, SLOT(appendText(QString const &)));
100 //connect(progress, SIGNAL(processFinished(QString const &)),
101 // this, SLOT(appendText(QString const &)));
102 connect(progress, SIGNAL(appendMessage(QString const &)),
103 this, SLOT(appendText(QString const &)));
104 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
105 this, SLOT(appendLyXErrText(QString const &)));
106 connect(progress, SIGNAL(appendError(QString const &)),
107 this, SLOT(appendText(QString const &)));
108 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
109 progress->lyxerrConnect();
114 void GuiProgressView::debugMessageActivated(QTreeWidgetItem * item, int)
119 QString const no = qt_("No");
120 QString const yes = qt_("Yes");
122 bool selected = (item->text(1) == yes);
123 item->setText(1, selected ? no : yes);
129 void GuiProgressView::levelChanged()
131 int level = Debug::NONE;
132 QTreeWidgetItemIterator it(widget_->debugMessagesTW);
134 if ((*it)->text(1) == qt_("Yes"))
135 level |= (*it)->data(0, Qt::UserRole).toInt();
138 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
142 void GuiProgressView::debugSelectionChanged()
144 int level = Debug::NONE;
145 if (widget_->debugAnyRB->isChecked())
147 else if (widget_->debugSelectedRB->isChecked()) {
148 widget_->debugMessagesTW->setEnabled(true);
152 widget_->debugMessagesTW->setEnabled(false);
153 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
157 void GuiProgressView::clearText()
159 if (widget_->autoClearCB->isChecked())
160 widget_->outTE->clear();
164 void GuiProgressView::appendLyXErrText(QString const & text)
166 widget_->outTE->moveCursor(QTextCursor::End);
167 widget_->outTE->insertPlainText(text);
168 widget_->outTE->ensureCursorVisible();
170 // Give the user a chance to disable debug messages because
171 // showing Debug::ANY messages completely blocks the GUI.
172 // Text is not always send as the whole line, so we must be
173 // careful about eolns.
174 if (text.endsWith("\n"))
175 QApplication::processEvents();
179 void GuiProgressView::appendText(QString const & text)
181 if (text.isEmpty() || !widget_->sbarCB->isChecked())
183 QString str = QTime::currentTime().toString();
185 if (!text.endsWith("\n"))
188 widget_->outTE->moveCursor(QTextCursor::End);
189 widget_->outTE->insertPlainText(str);
190 widget_->outTE->ensureCursorVisible();
194 void GuiProgressView::saveSession() const
196 Dialog::saveSession();
199 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
201 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
205 void GuiProgressView::restoreSession()
207 DockView::restoreSession();
209 widget_->autoClearCB->setChecked(
210 settings.value(sessionKey() + "/autoclear", true).toBool());
211 widget_->sbarCB->setChecked(
212 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
216 void GuiProgressView::showEvent(QShowEvent*)
218 ProgressInterface::instance()->lyxerrConnect();
222 void GuiProgressView::hideEvent(QHideEvent*)
224 ProgressInterface::instance()->lyxerrDisconnect();
228 Dialog * createGuiProgressView(GuiView & guiview)
231 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
233 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
239 } // namespace frontend
242 #include "moc_GuiProgressView.cpp"