]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiProgressView.cpp
d1d1de3391f39fdd073c27e351796a25d9b32d97
[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 #include <QGroupBox>
25 #include <QRadioButton>
26 #include <QButtonGroup>
27
28 namespace lyx {
29 namespace frontend {
30
31
32 struct LevelButton : QRadioButton
33 {
34         LevelButton(const QString& name) : QRadioButton(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         QButtonGroup* button_group = new QButtonGroup(this);
65         const std::vector<Debug::Type> levels = Debug::levels();
66         for (unsigned int i = 0; 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                 button_group->addButton(box);
71         }
72         connect(button_group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(levelChanged(QAbstractButton*)));
73         // TODO settings
74         button_group->buttons().front()->setChecked(true);
75         
76         GuiProgress* progress = dynamic_cast<GuiProgress*>(support::ProgressInterface::instance());
77
78         if (progress) {
79                 connect(progress, SIGNAL(processStarted(QString const &)), this, SLOT(appendText(QString const &)));
80                 //connect(progress, SIGNAL(processFinished(QString const &)), this, SLOT(appendText(QString const &)));
81                 connect(progress, SIGNAL(appendMessage(QString const &)), this, SLOT(appendText(QString const &)));
82                 connect(progress, SIGNAL(appendError(QString const &)), this, SLOT(appendText(QString const &)));
83                 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
84                 progress->lyxerrConnect();
85         }
86 }
87
88
89 void GuiProgressView::levelChanged(QAbstractButton* b)
90 {
91         LevelButton* lb = dynamic_cast<LevelButton*>(b);
92         if (lb)
93                 lyxerr.level(lb->level);
94 }
95
96
97 void GuiProgressView::clearText()
98 {
99         if (widget_->autoClearCB->isChecked())
100                 widget_->outTE->clear();
101 }
102
103
104 void GuiProgressView::appendText(QString const & text)
105 {
106         if (text.isEmpty())
107                 return;
108         QString time = QTime::currentTime().toString();
109         if (text.endsWith("\n"))
110                 widget_->outTE->insertPlainText(time + ": " + text);
111         else
112                 widget_->outTE->insertPlainText(text);
113
114         widget_->outTE->ensureCursorVisible();
115 }
116
117
118 void GuiProgressView::saveSession() const
119 {
120         Dialog::saveSession();
121         QSettings settings;
122         settings.setValue(
123                 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
124 }
125
126
127 void GuiProgressView::restoreSession()
128 {
129         DockView::restoreSession();
130         QSettings settings;
131         widget_->autoClearCB->setChecked(
132                 settings.value(sessionKey() + "/autoclear", true).toBool());
133 }
134
135
136 void GuiProgressView::showEvent(QShowEvent*)
137 {
138         support::ProgressInterface::instance()->lyxerrConnect();
139 }
140
141
142 void GuiProgressView::hideEvent(QHideEvent*)
143 {
144         support::ProgressInterface::instance()->lyxerrDisconnect();
145 }
146
147
148
149
150 Dialog * createGuiProgressView(GuiView & guiview)
151 {
152 #ifdef Q_WS_MACX
153         return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
154 #else
155         return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
156 #endif
157 }
158
159
160
161 } // namespace frontend
162 } // namespace lyx
163
164 #include "moc_GuiProgressView.cpp"