]> git.lyx.org Git - lyx.git/blobdiff - src/Changes.cpp
Check path of Qt tools if qtchooser is detected
[lyx.git] / src / Changes.cpp
index 9fa46f92a36708281f150212012dc87514696464..0d464d8fa26912b47e2dd74c78f2e0c70394366c 100644 (file)
 #include "BufferParams.h"
 #include "Encoding.h"
 #include "LaTeXFeatures.h"
+#include "MetricsInfo.h"
 #include "OutputParams.h"
 #include "Paragraph.h"
+#include "texstream.h"
 #include "TocBackend.h"
 
 #include "support/debug.h"
@@ -30,6 +32,8 @@
 #include "support/mutex.h"
 
 #include "frontends/alert.h"
+#include "frontends/FontMetrics.h"
+#include "frontends/Painter.h"
 
 #include <ostream>
 
@@ -37,6 +41,9 @@ using namespace std;
 
 namespace lyx {
 
+using frontend::Painter;
+using frontend::FontMetrics;
+
 /*
  * Class Change has a changetime field that specifies the exact time at which
  * a specific change was made. The change time is used as a guidance for the
@@ -138,6 +145,8 @@ void Changes::set(Change const & change, pos_type const start, pos_type const en
                        << ", author: " << change.author 
                        << ", time: " << long(change.changetime)
                        << ") in range (" << start << ", " << end << ")");
+               if (!isChanged())
+                       is_update_required_ = true;
        }
 
        Range const newRange(start, end);
@@ -298,8 +307,21 @@ bool Changes::isChanged(pos_type const start, pos_type const end) const
 }
 
 
+bool Changes::isChanged() const
+{
+       ChangeTable::const_iterator it = table_.begin();
+       ChangeTable::const_iterator const itend = table_.end();
+       for (; it != itend; ++it) {
+               if (it->change.changed())
+                       return true;
+       }
+       return false;
+}
+
+
 void Changes::merge()
 {
+       bool merged = false;
        ChangeTable::iterator it = table_.begin();
 
        while (it != table_.end()) {
@@ -312,6 +334,7 @@ void Changes::merge()
                                << it->range.start);
 
                        table_.erase(it);
+                       merged = true;
                        // start again
                        it = table_.begin();
                        continue;
@@ -330,6 +353,7 @@ void Changes::merge()
                        (it + 1)->change.changetime = max(it->change.changetime,
                                                          (it + 1)->change.changetime);
                        table_.erase(it);
+                       merged = true;
                        // start again
                        it = table_.begin();
                        continue;
@@ -337,6 +361,8 @@ void Changes::merge()
 
                ++it;
        }
+       if (merged && !isChanged())
+               is_update_required_ = true;
 }
 
 
@@ -504,17 +530,69 @@ void Changes::addToToc(DocIterator const & cdit, Buffer const & buffer,
                Toc::iterator it = TocBackend::findItem(*change_list, 0, author);
                if (it == change_list->end()) {
                        change_list->push_back(TocItem(dit, 0, author, true));
-                       change_list->push_back(TocItem(dit, 1, str, output_active,
-                               support::wrapParas(str, 4)));
+                       change_list->push_back(TocItem(dit, 1, str, output_active));
                        continue;
                }
                for (++it; it != change_list->end(); ++it) {
                        if (it->depth() == 0 && it->str() != author)
                                break;
                }
-               change_list->insert(it, TocItem(dit, 1, str, output_active,
-                       support::wrapParas(str, 4)));
+               change_list->insert(it, TocItem(dit, 1, str, output_active));
        }
 }
 
+
+void Changes::updateBuffer(Buffer const & buf)
+{
+       is_update_required_ = false;
+       if (!buf.areChangesPresent() && isChanged())
+               buf.setChangesPresent(true);
+}
+
+
+void Change::paintCue(PainterInfo & pi, double const x1, double const y,
+                      double const x2, FontInfo const & font) const
+{
+       if (!changed())
+               return;
+       // Calculate 1/3 height of font
+       FontMetrics const & fm = theFontMetrics(font);
+       double const y_bar = deleted() ? y - fm.maxAscent() / 3
+               : y + 2 * pi.base.solidLineOffset() + pi.base.solidLineThickness();
+       pi.pain.line(int(x1), int(y_bar), int(x2), int(y_bar), color(),
+                    Painter::line_solid, pi.base.solidLineThickness());
+}
+
+
+void Change::paintCue(PainterInfo & pi, double const x1, double const y1,
+                      double const x2, double const y2) const
+{
+       /*
+        * y1      /
+        *        /
+        *       /
+        *      /
+        *     /
+        * y2 /_____
+        *    x1  x2
+        */
+       switch(type) {
+       case UNCHANGED:
+               return;
+       case INSERTED:
+               pi.pain.line(int(x1), int(y2) + 1, int(x2), int(y2) + 1,
+                            color(), Painter::line_solid,
+                            pi.base.solidLineThickness());
+               return;
+       case DELETED:
+               // FIXME: we cannot use antialias since we keep drawing on the same
+               // background with the current painting mechanism.
+               pi.pain.line(int(x1), int(y2), int(x2), int(y1),
+                            color(), Painter::line_solid_aliased,
+                            pi.base.solidLineThickness());
+               return;
+       }
+}
+
+
 } // namespace lyx