]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiProgressView.cpp
Use QFontMetrics information for underlines (and friends) width and position
[lyx.git] / src / frontends / qt4 / GuiProgressView.cpp
index 004c70e86a69b1348dd07b434bd23c2775caa846..d6c9caf11a6e710bfb282a181af6cb646775b230 100644 (file)
@@ -16,6 +16,7 @@
 #include "GuiProgressView.h"
 
 #include "GuiApplication.h"
+#include "GuiProgress.h"
 #include "qt_helpers.h"
 
 #include "FuncRequest.h"
@@ -47,11 +48,23 @@ GuiProgressView::~GuiProgressView()
 }
 
 
+namespace{
+typedef pair<int, QString> DebugMap;
+typedef vector<DebugMap> DebugVector;
+
+bool DebugSorter(DebugMap const & a, DebugMap const & b)
+{
+       return a.second < b.second;
+}
+}
+
+
 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area, 
        Qt::WindowFlags flags)
        : DockView(parent, "progress", qt_("Progress/Debug Messages"), area, flags)
 {
-       widget_ = new ProgressViewWidget();
+       eol_last_ = true;
+       widget_ = new ProgressViewWidget;
        widget_->setMinimumHeight(150);
        widget_->debugMessagesTW->setSizePolicy(QSizePolicy::Ignored,
                                                QSizePolicy::Expanding);
@@ -59,7 +72,6 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
        setWidget(widget_);
 
        QFont font(guiApp->typewriterFontName());
-       font.setKerning(false);
        font.setFixedPitch(true);
        font.setStyleHint(QFont::TypeWriter);
        widget_->outTE->setFont(font);
@@ -76,15 +88,25 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
 
        // ignore Debug::NONE and Debug::ANY
        int const level_count = Debug::levelCount() - 1;
+       DebugVector dmap;
+       for (int i = 1 ; i < level_count; i++) {
+               Debug::Type const level = Debug::value(i);
+               QString const desc = qt_(Debug::description(level));
+               dmap.push_back(DebugMap(level, desc));
+       }
+       sort(dmap.begin(), dmap.end(), DebugSorter);
+
        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++) {
+
+       DebugVector::const_iterator dit = dmap.begin();
+       DebugVector::const_iterator const den = dmap.end();
+       for (; dit != den; ++dit) {
                item = new QTreeWidgetItem(widget_->debugMessagesTW);
-               Debug::Type const level = Debug::value(i);
-               item->setText(0, qt_(Debug::description(level)));
-               item->setData(0, Qt::UserRole, int(level));
+               item->setText(0, dit->second);
+               item->setData(0, Qt::UserRole, int(dit->first));
                item->setText(1, qt_("No"));
        }
        widget_->debugMessagesTW->resizeColumnToContents(0);
@@ -104,7 +126,7 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
                connect(progress, SIGNAL(appendMessage(QString const &)),
                        this, SLOT(appendText(QString const &)));
                connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
-                       this, SLOT(appendLyXErrText(QString const &)));
+                       this, SLOT(appendLyXErrText(QString const &)), Qt::QueuedConnection);
                connect(progress, SIGNAL(appendError(QString const &)),
                        this, SLOT(appendText(QString const &)));
                connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
@@ -151,6 +173,12 @@ void GuiProgressView::debugSelectionChanged()
                levelChanged();
                return;
        }
+       QTreeWidgetItemIterator it(widget_->debugMessagesTW);
+       while (*it) {
+               (*it)->setText(1, level == Debug::NONE ?
+                               qt_("No") : qt_("Yes"));
+               ++it;
+       }
        widget_->debugMessagesTW->setEnabled(false);
        dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
 }
@@ -158,8 +186,10 @@ void GuiProgressView::debugSelectionChanged()
 
 void GuiProgressView::clearText()
 {
-       if (widget_->autoClearCB->isChecked())
+       if (widget_->autoClearCB->isChecked()){
                widget_->outTE->clear();
+               eol_last_ = true;
+       }
 }
 
 
@@ -168,15 +198,17 @@ void GuiProgressView::appendLyXErrText(QString const & text)
        widget_->outTE->moveCursor(QTextCursor::End);
        widget_->outTE->insertPlainText(text);
        widget_->outTE->ensureCursorVisible();
-
+       eol_last_ = false;
        // Give the user a chance to disable debug messages because
        // 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"))
+       if (text.endsWith("\n")) {
+               eol_last_ = true;
                QApplication::processEvents();
+       }
 }
 
 
@@ -184,10 +216,11 @@ void GuiProgressView::appendText(QString const & text)
 {
        if (text.isEmpty() || !widget_->sbarCB->isChecked())
                return;
-       QString str = QTime::currentTime().toString();
+       QString str = GuiProgress::currentTime();
        str += ": " + text;
-       if (!text.endsWith("\n"))
-               str += "\n";
+       if (!eol_last_)
+               str = "\n" + str;
+       eol_last_ = text.endsWith("\n");
 
        widget_->outTE->moveCursor(QTextCursor::End);
        widget_->outTE->insertPlainText(str);
@@ -231,11 +264,7 @@ void GuiProgressView::hideEvent(QHideEvent*)
 
 Dialog * createGuiProgressView(GuiView & guiview)
 {
-#ifdef Q_WS_MACX
-       return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
-#else
        return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
-#endif
 }