]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiProgressView.cpp
Remove unused UI file.
[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 #include <QDebug>
29
30 using namespace std;
31 using namespace lyx::support;
32
33 namespace lyx {
34 namespace frontend {
35
36
37 struct LevelButton : QCheckBox
38 {
39         LevelButton(const QString& name) : QCheckBox(name) {}
40         Debug::Type level;
41         
42         void setCheckStatusSilent(Qt::CheckState state) {
43                 blockSignals(true);
44                 setCheckState(state);
45                 blockSignals(false);    
46         }
47 };
48
49
50 ProgressViewWidget::ProgressViewWidget()
51 {
52         setupUi(this);
53
54 }
55
56
57 GuiProgressView::~GuiProgressView()
58 {
59         delete widget_;
60 }
61
62
63 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area, 
64         Qt::WindowFlags flags) : DockView(parent, "progress", "Debug/Progress window", area, flags)
65 {
66         widget_ = new ProgressViewWidget();
67 #if QT_VERSION < 0x040400
68         widget_->scrollArea->setWidget(widget_->scrollAreaWidgetContents);
69 #endif
70         widget_->setMinimumHeight(150);
71         widget_->adjustSize();
72         setWidget(widget_);
73
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);
80
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)));
87
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)));
93                 box->level = level;
94                 widget_->settingsLayout->addWidget(box, (i + 3) % 10, (i + 3) / 10);
95                 box->setChecked(false);
96                 level_buttons << box;
97                 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
98         }
99         widget_->settingsLayout->activate();
100         
101         GuiProgress * progress =
102                 dynamic_cast<GuiProgress *>(ProgressInterface::instance());
103
104         if (progress) {
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();
117         }
118 }
119
120
121 void GuiProgressView::levelChanged()
122 {
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;
129                 }
130         }
131         dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
132         
133         toggle_button->setCheckStatusSilent (Qt::PartiallyChecked);
134 }
135
136
137 void GuiProgressView::tristateChanged(int state)
138 {
139         if (state != Qt::PartiallyChecked) {
140                 Q_FOREACH(LevelButton* button, level_buttons) {
141                         button->setCheckStatusSilent(toggle_button->checkState());
142                 }
143                 int level = (state == Qt::Checked ? Debug::ANY : Debug::NONE);
144                 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
145         } else {
146                 Q_FOREACH(LevelButton* button, checked_buttons) {
147                         button->setCheckStatusSilent(Qt::Checked);
148                 }
149                 levelChanged();
150         }
151 }
152
153
154 void GuiProgressView::clearText()
155 {
156         if (widget_->autoClearCB->isChecked())
157                 widget_->outTE->clear();
158 }
159
160
161 void GuiProgressView::appendLyXErrText(QString const & text)
162 {
163         widget_->outTE->insertPlainText(text);
164         widget_->outTE->ensureCursorVisible();
165
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();
172 }
173
174
175 void GuiProgressView::appendText(QString const & text)
176 {
177         if (text.isEmpty() || !widget_->sbarCB->isChecked())
178                 return;
179         QString str = QTime::currentTime().toString();
180         str += ": " + text;
181         if (!text.endsWith("\n"))
182                 str += "\n";
183
184         widget_->outTE->insertPlainText(str);
185         widget_->outTE->ensureCursorVisible();
186 }
187
188
189 void GuiProgressView::saveSession() const
190 {
191         Dialog::saveSession();
192         QSettings settings;
193         settings.setValue(
194                 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
195         settings.setValue(
196                 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
197 }
198
199
200 void GuiProgressView::restoreSession()
201 {
202         DockView::restoreSession();
203         QSettings settings;
204         widget_->autoClearCB->setChecked(
205                 settings.value(sessionKey() + "/autoclear", true).toBool());
206         widget_->sbarCB->setChecked(
207                 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
208 }
209
210
211 void GuiProgressView::showEvent(QShowEvent*)
212 {
213         ProgressInterface::instance()->lyxerrConnect();
214 }
215
216
217 void GuiProgressView::hideEvent(QHideEvent*)
218 {
219         ProgressInterface::instance()->lyxerrDisconnect();
220 }
221
222
223
224
225 Dialog * createGuiProgressView(GuiView & guiview)
226 {
227 #ifdef Q_WS_MACX
228         return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
229 #else
230         return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
231 #endif
232 }
233
234
235
236 } // namespace frontend
237 } // namespace lyx
238
239 #include "moc_GuiProgressView.cpp"