]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiProgressView.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiProgressView.cpp
index 3ca2e7b187b1d5ec5819a2c5e2f494acfbd87db3..004c70e86a69b1348dd07b434bd23c2775caa846 100644 (file)
@@ -6,6 +6,7 @@
  *
  * \author Peter Kümmel
  * \author Pavel Sanda
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 #include <config.h>
 
 #include "GuiProgressView.h"
-#include "GuiApplication.h"
 
+#include "GuiApplication.h"
 #include "qt_helpers.h"
+
 #include "FuncRequest.h"
 
-#include "support/debug.h"
 #include "support/convert.h"
+#include "support/debug.h"
 
+#include <QCheckBox>
+#include <QDebug>
 #include <QSettings>
 #include <QTime>
 
-#include <QCheckBox>
-
 using namespace std;
 using namespace lyx::support;
 
@@ -33,17 +35,9 @@ namespace lyx {
 namespace frontend {
 
 
-struct LevelButton : QCheckBox
-{
-       LevelButton(const QString& name) : QCheckBox(name) {}
-       Debug::Type level;
-};
-
-
 ProgressViewWidget::ProgressViewWidget()
 {
        setupUi(this);
-
 }
 
 
@@ -54,9 +48,14 @@ GuiProgressView::~GuiProgressView()
 
 
 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area, 
-       Qt::WindowFlags flags) : DockView(parent, "progress", "Debug/Progress window", area, flags)
+       Qt::WindowFlags flags)
+       : DockView(parent, "progress", qt_("Progress/Debug Messages"), area, flags)
 {
        widget_ = new ProgressViewWidget();
+       widget_->setMinimumHeight(150);
+       widget_->debugMessagesTW->setSizePolicy(QSizePolicy::Ignored,
+                                               QSizePolicy::Expanding);
+       widget_->adjustSize();
        setWidget(widget_);
 
        QFont font(guiApp->typewriterFontName());
@@ -66,26 +65,34 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
        widget_->outTE->setFont(font);
        widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
 
-       Debug::Type const levels = lyxerr.level();
-       // number of initial items in settings tab
-       int const level_count = Debug::levelCount();
-       for (int i = 0 ; i < level_count; i++) {
+       connect(widget_->debugNoneRB, SIGNAL(clicked()),
+               this, SLOT(debugSelectionChanged()));
+       connect(widget_->debugSelectedRB, SIGNAL(clicked()),
+               this, SLOT(debugSelectionChanged()));
+       connect(widget_->debugAnyRB, SIGNAL(clicked()),
+               this, SLOT(debugSelectionChanged()));
+       widget_->debugMessagesTW->setEnabled(false);
+       widget_->debugNoneRB->setChecked(true);
+
+       // ignore Debug::NONE and Debug::ANY
+       int const level_count = Debug::levelCount() - 1;
+       QTreeWidgetItem * item = 0;
+       widget_->debugMessagesTW->setColumnCount(2);
+       widget_->debugMessagesTW->headerItem()->setText(0, qt_("Debug Level"));
+       widget_->debugMessagesTW->headerItem()->setText(1, qt_("Set"));
+       for (int i = 1 ; i < level_count; i++) {
+               item = new QTreeWidgetItem(widget_->debugMessagesTW);
                Debug::Type const level = Debug::value(i);
-               LevelButton * box = new LevelButton(toqstr(Debug::description(level)));
-               box->level = level;
-               widget_->settingsLayout->addWidget(box, (i + 3) % 10, (i + 3) / 10);
-
-               if ((levels == Debug::ANY) && (levels == level))
-                       box->setChecked(true);
-               else
-                       if ((level != Debug::ANY) && (levels & level))
-                               box->setChecked(true);
-
-               level_buttons << box;
-               connect(box, SIGNAL(stateChanged(int)), this, SLOT(levelChanged()));
+               item->setText(0, qt_(Debug::description(level)));
+               item->setData(0, Qt::UserRole, int(level));
+               item->setText(1, qt_("No"));
        }
-
-
+       widget_->debugMessagesTW->resizeColumnToContents(0);
+       widget_->debugMessagesTW->resizeColumnToContents(1);
+       connect(widget_->debugMessagesTW,
+               SIGNAL(itemActivated(QTreeWidgetItem *, int)),
+               this, SLOT(debugMessageActivated(QTreeWidgetItem *, int)));
+  
        GuiProgress * progress =
                dynamic_cast<GuiProgress *>(ProgressInterface::instance());
 
@@ -106,20 +113,45 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
 }
 
 
+void GuiProgressView::debugMessageActivated(QTreeWidgetItem * item, int)
+{
+       if (item == 0)
+               return;
+
+       QString const no = qt_("No");
+       QString const yes = qt_("Yes");
+
+       bool selected = (item->text(1) == yes);
+       item->setText(1, selected ? no : yes);
+
+       levelChanged();
+}
+
+
 void GuiProgressView::levelChanged()
 {
        int level = Debug::NONE;
-       Q_FOREACH(const LevelButton* button, level_buttons) {
-               if (button->isChecked()) {
-                       // Debug::NONE overwrites other levels
-                       if (button->level == Debug::NONE) {
-                               level = Debug::NONE;
-                               break;
-                       } else {
-                               level |= button->level;
-                       }
-               }
+       QTreeWidgetItemIterator it(widget_->debugMessagesTW);
+       while (*it) {
+               if ((*it)->text(1) == qt_("Yes"))
+                       level |= (*it)->data(0, Qt::UserRole).toInt();
+               ++it;
+       }
+       dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
+}
+
+
+void GuiProgressView::debugSelectionChanged()
+{
+       int level = Debug::NONE;
+       if (widget_->debugAnyRB->isChecked())
+               level = Debug::ANY;
+       else if (widget_->debugSelectedRB->isChecked()) {
+               widget_->debugMessagesTW->setEnabled(true);
+               levelChanged();
+               return;
        }
+       widget_->debugMessagesTW->setEnabled(false);
        dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
 }
 
@@ -133,6 +165,7 @@ void GuiProgressView::clearText()
 
 void GuiProgressView::appendLyXErrText(QString const & text)
 {
+       widget_->outTE->moveCursor(QTextCursor::End);
        widget_->outTE->insertPlainText(text);
        widget_->outTE->ensureCursorVisible();
 
@@ -140,6 +173,8 @@ void GuiProgressView::appendLyXErrText(QString const & text)
        // showing Debug::ANY messages completely blocks the GUI.
        // Text is not always send as the whole line, so we must be
        // careful about eolns.
+       // WARNING: processing events could cause crashes!
+       // TODO: find a better solution
        if (text.endsWith("\n"))
                QApplication::processEvents();
 }
@@ -154,6 +189,7 @@ void GuiProgressView::appendText(QString const & text)
        if (!text.endsWith("\n"))
                str += "\n";
 
+       widget_->outTE->moveCursor(QTextCursor::End);
        widget_->outTE->insertPlainText(str);
        widget_->outTE->ensureCursorVisible();
 }
@@ -193,8 +229,6 @@ void GuiProgressView::hideEvent(QHideEvent*)
 }
 
 
-
-
 Dialog * createGuiProgressView(GuiView & guiview)
 {
 #ifdef Q_WS_MACX