]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiProgressView.cpp
5554bb952c87425c24de2e4d342a5dbeb462a1bb
[lyx.git] / src / frontends / qt4 / GuiProgressView.cpp
1 // -*- C++ -*-
2 /**
3  * \file GuiProgressView.cpp
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Peter Kümmel
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiProgressView.h"
15 #include "GuiApplication.h"
16
17 #include "qt_helpers.h"
18
19 #include "support/debug.h"
20
21 #include <QSettings>
22 #include <QTime>
23
24
25 namespace lyx {
26 namespace frontend {
27
28
29 ProgressViewWidget::ProgressViewWidget()
30 {
31         setupUi(this);
32
33 }
34
35
36 GuiProgressView::~GuiProgressView()
37 {
38         delete widget_;
39 }
40
41
42 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area, 
43         Qt::WindowFlags flags) : DockView(parent, "progress", "Debug/Progress window", area, flags)
44 {
45         widget_ = new ProgressViewWidget();
46         setWidget(widget_);
47
48         QFont font(guiApp->typewriterFontName());
49         font.setKerning(false);
50         font.setFixedPitch(true);
51         font.setStyleHint(QFont::TypeWriter);
52         widget_->outTE->setFont(font);
53
54         GuiProgress* progress = dynamic_cast<GuiProgress*>(support::ProgressInterface::instance());
55
56         if (progress) {
57                 connect(progress, SIGNAL(processStarted(QString const &)), this, SLOT(appendText(QString const &)));
58                 //connect(progress, SIGNAL(processFinished(QString const &)), this, SLOT(appendText(QString const &)));
59                 connect(progress, SIGNAL(appendMessage(QString const &)), this, SLOT(appendText(QString const &)));
60                 connect(progress, SIGNAL(appendError(QString const &)), this, SLOT(appendText(QString const &)));
61                 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
62         }
63 }
64
65
66 void GuiProgressView::clearText()
67 {
68         if (widget_->autoClearCB->isChecked())
69                 widget_->outTE->clear();
70 }
71
72
73 void GuiProgressView::appendText(QString const & text)
74 {
75         if (text.isEmpty())
76                 return;
77         QString time = QTime::currentTime().toString();
78         widget_->outTE->insertPlainText(time + ": " + text.trimmed() + "\n");
79         widget_->outTE->ensureCursorVisible();
80 }
81
82 void GuiProgressView::saveSession() const
83 {
84         Dialog::saveSession();
85         QSettings settings;
86         settings.setValue(
87                 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
88 }
89
90 void GuiProgressView::restoreSession()
91 {
92         DockView::restoreSession();
93         QSettings settings;
94         widget_->autoClearCB->setChecked(
95                 settings.value(sessionKey() + "/autoclear", true).toBool());
96 }
97
98
99 Dialog * createGuiProgressView(GuiView & guiview)
100 {
101 #ifdef Q_WS_MACX
102         return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
103 #else
104         return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
105 #endif
106 }
107
108
109
110 } // namespace frontend
111 } // namespace lyx
112
113 #include "moc_GuiProgressView.cpp"