]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiProgressView.cpp
06d53344aa5d614c26b24626e7e47ba82ce09640
[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         widget_->tabWidget->widget(0)->setContentsMargins(-5,-7,0,-7);
66
67
68         const int levelCount = Debug::levelCount();
69         for (int i = 1; i <= levelCount; i++) {
70                 const Debug::Type level = Debug::value(i);
71                 LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
72                 box->level = level;
73                 widget_->settingsLayout->addWidget(box,i%10,i/10);
74                 // TODO settings
75                 box->setChecked(false);
76                 level_buttons << box;
77                 connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
78         }
79
80         
81         GuiProgress* progress = dynamic_cast<GuiProgress*>(support::ProgressInterface::instance());
82
83         if (progress) {
84                 connect(progress, SIGNAL(processStarted(QString const &)), this, SLOT(appendText(QString const &)));
85                 //connect(progress, SIGNAL(processFinished(QString const &)), this, SLOT(appendText(QString const &)));
86                 connect(progress, SIGNAL(appendMessage(QString const &)), this, SLOT(appendText(QString const &)));
87                 connect(progress, SIGNAL(appendError(QString const &)), this, SLOT(appendText(QString const &)));
88                 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
89                 progress->lyxerrConnect();
90         }
91 }
92
93
94 void GuiProgressView::levelChanged()
95 {
96         int level = Debug::NONE;
97         Q_FOREACH(const LevelButton* button, level_buttons) {
98                 if (button->isChecked()) {
99                         // Debug::NONE overwrites other levels
100                         if (button->level == Debug::NONE) {
101                                 level = Debug::NONE;
102                                 break;
103                         } else {
104                                 level |= button->level;
105                         }
106                 }
107         }
108         dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<std::string>(level)));
109 }
110
111
112 void GuiProgressView::clearText()
113 {
114         if (widget_->autoClearCB->isChecked())
115                 widget_->outTE->clear();
116 }
117
118
119 void GuiProgressView::appendText(QString const & text)
120 {
121         if (text.isEmpty())
122                 return;
123         QString time = QTime::currentTime().toString();
124         if (text.endsWith("\n"))
125                 widget_->outTE->insertPlainText(time + ": " + text);
126         else
127                 widget_->outTE->insertPlainText(text);
128
129         widget_->outTE->ensureCursorVisible();
130 }
131
132
133 void GuiProgressView::saveSession() const
134 {
135         Dialog::saveSession();
136         QSettings settings;
137         settings.setValue(
138                 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
139 }
140
141
142 void GuiProgressView::restoreSession()
143 {
144         DockView::restoreSession();
145         QSettings settings;
146         widget_->autoClearCB->setChecked(
147                 settings.value(sessionKey() + "/autoclear", true).toBool());
148 }
149
150
151 void GuiProgressView::showEvent(QShowEvent*)
152 {
153         support::ProgressInterface::instance()->lyxerrConnect();
154 }
155
156
157 void GuiProgressView::hideEvent(QHideEvent*)
158 {
159         support::ProgressInterface::instance()->lyxerrDisconnect();
160 }
161
162
163
164
165 Dialog * createGuiProgressView(GuiView & guiview)
166 {
167 #ifdef Q_WS_MACX
168         return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
169 #else
170         return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
171 #endif
172 }
173
174
175
176 } // namespace frontend
177 } // namespace lyx
178
179 #include "moc_GuiProgressView.cpp"