]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiProgressView.cpp
More notes.
[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  * \author Pavel Sanda
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiProgressView.h"
16 #include "GuiApplication.h"
17
18 #include "qt_helpers.h"
19 #include "FuncRequest.h"
20
21 #include "support/debug.h"
22 #include "support/convert.h"
23
24 #include <QSettings>
25 #include <QTime>
26
27 #include <QCheckBox>
28
29
30 namespace lyx {
31 namespace frontend {
32
33
34 struct LevelButton : QCheckBox
35 {
36         LevelButton(const QString& name) : QCheckBox(name) {}
37         Debug::Type level;
38 };
39
40
41 ProgressViewWidget::ProgressViewWidget()
42 {
43         setupUi(this);
44
45 }
46
47
48 GuiProgressView::~GuiProgressView()
49 {
50         delete widget_;
51 }
52
53
54 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area, 
55         Qt::WindowFlags flags) : DockView(parent, "progress", "Debug/Progress window", area, flags)
56 {
57         widget_ = new ProgressViewWidget();
58         setWidget(widget_);
59
60         QFont font(guiApp->typewriterFontName());
61         font.setKerning(false);
62         font.setFixedPitch(true);
63         font.setStyleHint(QFont::TypeWriter);
64         widget_->outTE->setFont(font);
65
66
67         const int levelCount = Debug::levelCount();
68         for (int i = 0; i < levelCount; i++) {
69                 const Debug::Type level = Debug::value(i);
70                 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
71                 box->level = level;
72                 widget_->settingsLayout->addWidget(box);
73                 // TODO settings
74                 box->setChecked(false);
75                 level_buttons << box;
76                 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
77         }
78
79         
80         GuiProgress* progress = dynamic_cast<GuiProgress*>(support::ProgressInterface::instance());
81
82         if (progress) {
83                 connect(progress, SIGNAL(processStarted(QString const &)), this, SLOT(appendText(QString const &)));
84                 //connect(progress, SIGNAL(processFinished(QString const &)), this, SLOT(appendText(QString const &)));
85                 connect(progress, SIGNAL(appendMessage(QString const &)), this, SLOT(appendText(QString const &)));
86                 connect(progress, SIGNAL(appendError(QString const &)), this, SLOT(appendText(QString const &)));
87                 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
88                 progress->lyxerrConnect();
89         }
90 }
91
92
93 void GuiProgressView::levelChanged()
94 {
95         int level = Debug::NONE;
96         Q_FOREACH(const LevelButton* button, level_buttons) {
97                 if (button->isChecked()) {
98                         // Debug::NONE overwrites other levels
99                         if (button->level == Debug::NONE) {
100                                 level = Debug::NONE;
101                                 break;
102                         } else {
103                                 level |= button->level;
104                         }
105                 }
106         }
107         dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<std::string>(level)));
108 }
109
110
111 void GuiProgressView::clearText()
112 {
113         if (widget_->autoClearCB->isChecked())
114                 widget_->outTE->clear();
115 }
116
117
118 void GuiProgressView::appendText(QString const & text)
119 {
120         if (text.isEmpty())
121                 return;
122         QString time = QTime::currentTime().toString();
123         if (text.endsWith("\n"))
124                 widget_->outTE->insertPlainText(time + ": " + text);
125         else
126                 widget_->outTE->insertPlainText(text);
127
128         widget_->outTE->ensureCursorVisible();
129 }
130
131
132 void GuiProgressView::saveSession() const
133 {
134         Dialog::saveSession();
135         QSettings settings;
136         settings.setValue(
137                 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
138 }
139
140
141 void GuiProgressView::restoreSession()
142 {
143         DockView::restoreSession();
144         QSettings settings;
145         widget_->autoClearCB->setChecked(
146                 settings.value(sessionKey() + "/autoclear", true).toBool());
147 }
148
149
150 void GuiProgressView::showEvent(QShowEvent*)
151 {
152         support::ProgressInterface::instance()->lyxerrConnect();
153 }
154
155
156 void GuiProgressView::hideEvent(QHideEvent*)
157 {
158         support::ProgressInterface::instance()->lyxerrDisconnect();
159 }
160
161
162
163
164 Dialog * createGuiProgressView(GuiView & guiview)
165 {
166 #ifdef Q_WS_MACX
167         return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
168 #else
169         return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
170 #endif
171 }
172
173
174
175 } // namespace frontend
176 } // namespace lyx
177
178 #include "moc_GuiProgressView.cpp"