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