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_->debugMessagesTW->setSizePolicy(QSizePolicy::Ignored,
57 QSizePolicy::Expanding);
58 widget_->adjustSize();
61 QFont font(guiApp->typewriterFontName());
62 font.setKerning(false);
63 font.setFixedPitch(true);
64 font.setStyleHint(QFont::TypeWriter);
65 widget_->outTE->setFont(font);
66 widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
68 connect(widget_->debugNoneRB, SIGNAL(clicked()),
69 this, SLOT(debugSelectionChanged()));
70 connect(widget_->debugSelectedRB, SIGNAL(clicked()),
71 this, SLOT(debugSelectionChanged()));
72 connect(widget_->debugAnyRB, SIGNAL(clicked()),
73 this, SLOT(debugSelectionChanged()));
74 widget_->debugMessagesTW->setEnabled(false);
75 widget_->debugNoneRB->setChecked(true);
77 // ignore Debug::NONE and Debug::ANY
78 int const level_count = Debug::levelCount() - 1;
79 QTreeWidgetItem * item = 0;
80 widget_->debugMessagesTW->setColumnCount(2);
81 widget_->debugMessagesTW->headerItem()->setText(0, qt_("Debug Level"));
82 widget_->debugMessagesTW->headerItem()->setText(1, qt_("Set"));
83 for (int i = 1 ; i < level_count; i++) {
84 item = new QTreeWidgetItem(widget_->debugMessagesTW);
85 Debug::Type const level = Debug::value(i);
86 item->setText(0, qt_(Debug::description(level)));
87 item->setData(0, Qt::UserRole, int(level));
88 item->setText(1, qt_("No"));
90 widget_->debugMessagesTW->resizeColumnToContents(0);
91 widget_->debugMessagesTW->resizeColumnToContents(1);
92 connect(widget_->debugMessagesTW,
93 SIGNAL(itemActivated(QTreeWidgetItem *, int)),
94 this, SLOT(debugMessageActivated(QTreeWidgetItem *, int)));
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::debugMessageActivated(QTreeWidgetItem * item, int)
121 QString const no = qt_("No");
122 QString const yes = qt_("Yes");
124 bool selected = (item->text(1) == yes);
125 item->setText(1, selected ? no : yes);
131 void GuiProgressView::levelChanged()
133 int level = Debug::NONE;
134 QTreeWidgetItemIterator it(widget_->debugMessagesTW);
136 if ((*it)->text(1) == qt_("Yes"))
137 level |= (*it)->data(0, Qt::UserRole).toInt();
140 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
144 void GuiProgressView::debugSelectionChanged()
146 int level = Debug::NONE;
147 if (widget_->debugAnyRB->isChecked())
149 else if (widget_->debugSelectedRB->isChecked()) {
150 widget_->debugMessagesTW->setEnabled(true);
154 widget_->debugMessagesTW->setEnabled(false);
155 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
159 void GuiProgressView::clearText()
161 if (widget_->autoClearCB->isChecked())
162 widget_->outTE->clear();
166 void GuiProgressView::appendLyXErrText(QString const & text)
168 widget_->outTE->moveCursor(QTextCursor::End);
169 widget_->outTE->insertPlainText(text);
170 widget_->outTE->ensureCursorVisible();
172 // Give the user a chance to disable debug messages because
173 // showing Debug::ANY messages completely blocks the GUI.
174 // Text is not always send as the whole line, so we must be
175 // careful about eolns.
176 if (text.endsWith("\n"))
177 QApplication::processEvents();
181 void GuiProgressView::appendText(QString const & text)
183 if (text.isEmpty() || !widget_->sbarCB->isChecked())
185 QString str = QTime::currentTime().toString();
187 if (!text.endsWith("\n"))
190 widget_->outTE->moveCursor(QTextCursor::End);
191 widget_->outTE->insertPlainText(str);
192 widget_->outTE->ensureCursorVisible();
196 void GuiProgressView::saveSession() const
198 Dialog::saveSession();
201 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
203 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
207 void GuiProgressView::restoreSession()
209 DockView::restoreSession();
211 widget_->autoClearCB->setChecked(
212 settings.value(sessionKey() + "/autoclear", true).toBool());
213 widget_->sbarCB->setChecked(
214 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
218 void GuiProgressView::showEvent(QShowEvent*)
220 ProgressInterface::instance()->lyxerrConnect();
224 void GuiProgressView::hideEvent(QHideEvent*)
226 ProgressInterface::instance()->lyxerrDisconnect();
230 Dialog * createGuiProgressView(GuiView & guiview)
233 return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
235 return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
241 } // namespace frontend
244 #include "moc_GuiProgressView.cpp"