{"thread":{"id":"6038","subject":"[PATCH qgit] Change also tag marks when changing graph size","startedAt":"2006-10-24T16:47:38Z","lastAt":"2006-10-25T02:20:12Z","messageCount":4,"participants":["Marco Costalba","Josef Weidendorfer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"29871","messageId":"e5bfff550610240947i30bc3fc0x49710e4cbb0f0556@mail.gmail.com","threadId":"6038","inReplyTo":null,"subject":"[PATCH qgit] Change also tag marks when changing graph size","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2006-10-24T16:47:38Z","receivedAt":"2006-10-24T16:47:38Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"When changing graph size with CTRL+ and CTRL-\nupdate also tag/branch marks.\n\nAlso little cleanup.\n---\n\nHi Josef,\n\n  please tell me if you are working on the same files, in this case I\nwill step back and wait you to finish your patch series and eventually\nresubmit this one at the end.\n\n   Marco\n\n\n  src/listview.cpp |  116 ++++++++++++++++++++++++++++-------------------------\n  src/listview.h   |   11 ++---\n 2 files changed, 66 insertions(+), 61 deletions(-)\n\ndiff --git a/src/listview.cpp b/src/listview.cpp\nindex 7251b97..1e33ac0 100644\n--- a/src/listview.cpp\n+++ b/src/listview.cpp\n@@ -224,8 +224,7 @@ void ListView::on_newRevsAdded(const Fil\n\n  \tfor (uint i = lv->childCount(); i < shaVec.count(); i++) {\n  \t\tlastItem = new ListViewItem(lv, lastItem, git, shaVec[i],\n-\t\t                            d->m()->gm.laneWidth,\n-\t\t\t\t\t    evenLine, secs, fh);\n+\t\t                            d->m()->gm.laneWidth, evenLine, secs, fh);\n  \t\tevenLine = !evenLine;\n \t}\n }\n@@ -539,24 +538,23 @@ #undef R_CENTER\n\n }\n\n-\n  void ListViewItem::paintGraph(const Rev& c, QPainter* p,\n-\t\t\t      const QColorGroup& cg, int width) {\n+                              const QColorGroup& cg, int width) {\n\n-        static QColor colors[COLORS_NUM] = {Qt::black, Qt::red, DARK_GREEN,\n-\t\t\t\t\t    Qt::blue,  Qt::darkGray, BROWN,\n-\t\t\t\t\t    Qt::magenta, ORANGE};\n+\tstatic QColor colors[COLORS_NUM] = { Qt::black, Qt::red, DARK_GREEN,\n+\t                                     Qt::blue,  Qt::darkGray, BROWN,\n+\t                                     Qt::magenta, ORANGE };\n\n  \tQListView* lv = listView();\n  \tif (!lv)\n \t\treturn;\n\n  \tQColorGroup::ColorRole crole = QColorGroup::Base;\n-\tif ( isSelected() && lv->allColumnsShowFocus() )\n-\t    crole = QColorGroup::Highlight;\n+\tif (isSelected() && lv->allColumnsShowFocus())\n+\t\tcrole = QColorGroup::Highlight;\n\n-\tQBrush back = cg.brush( crole );\n-\tp->fillRect( 0, 0, width, height(), back );\n+\tQBrush back = cg.brush(crole);\n+\tp->fillRect(0, 0, width, height(), back);\n\n  \tconst QValueVector<int>& lanes(c.lanes);\n  \tuint laneNum = lanes.count();\n@@ -567,27 +565,24 @@ void ListViewItem::paintGraph(const Rev&\n \t\t\tbreak;\n \t\t}\n\n-\tint x1 = 0, x2;\n-\tfor (uint i = 0; i < laneNum && x1 < width; i++, x1 = x2) {\n-\t        x2 = x1 + laneWidth;\n+\tint x1 = 0, x2 = 0;\n+\tfor (uint i = 0; i < laneNum && x1 < width; i++) {\n+\n+\t\tx1 = x2;\n+\t\tx2 += laneWidth;\n\n \t\tint ln = lanes[i];\n \t\tif (ln == EMPTY)\n-\t\t    continue;\n-\n-\t\tint type = ln;\n-\t\tif (ln == CROSS)\n-\t\t    type = NOT_ACTIVE;\n+\t\t\tcontinue;\n\n \t\tint col = (   isHead(ln) || isTail(ln) || isJoin(ln)\n-\t\t\t      || ln == CROSS_EMPTY) ? mergeLane : i;\n-\n-\t\tpaintGraphLane(p, type, x1, x2,\n-\t\t\t       colors[col % COLORS_NUM], back);\n+\t\t           || ln == CROSS_EMPTY) ? mergeLane : i;\n\n-\t\tif (ln == CROSS)\n-\t\t    paintGraphLane(p, CROSS, x1, x2,\n-\t\t\t\t   colors[mergeLane % COLORS_NUM], back);\n+\t\tif (ln == CROSS) {\n+\t\t\tpaintGraphLane(p, NOT_ACTIVE, x1, x2, colors[col % COLORS_NUM], back);\n+\t\t\tpaintGraphLane(p, CROSS, x1, x2, colors[mergeLane % COLORS_NUM], back);\n+\t\t} else\n+\t\t\tpaintGraphLane(p, ln, x1, x2, colors[col % COLORS_NUM], back);\n \t}\n }\n\n@@ -601,7 +596,7 @@ void ListViewItem::paintCell(QPainter* p\n  \t\tsetupData(c);\n\n \tif (column == GRAPH_COL) {\n-\t        paintGraph(c, p, _cg, width);\n+\t\tpaintGraph(c, p, _cg, width);\n \t\treturn;\n \t}\n\n@@ -615,6 +610,8 @@ void ListViewItem::paintCell(QPainter* p\n \t// tags, heads, refs and working dir colouring\n \tif (mycolumn == LOG_COL) {\n\n+\t\tpaintTagMarks(column, c);\n+\n \t\tif (isHighlighted) {\n  \t\t\tQFont f(p->font());\n  \t\t\tf.setBold(true);\n@@ -638,37 +635,56 @@ void ListViewItem::paintCell(QPainter* p\n \t\tp->restore();\n }\n\n-void ListViewItem::addTextPixmap(SCRef text, const QColor& color, bool bold) {\n+void ListViewItem::paintTagMarks(int col, const Rev& c) {\n\n-\tint col = LOG_COL + (fh ? 0 : -1);\n-\tQStringList sl = QStringList::split('\\n', text);\n-\tloopList(it, sl) {\n-\t\tQPixmap* pm = doAddTextPixmap(*it, color, col, bold);\n-\t\tsetPixmap(col, *pm);\n-\t\tdelete pm;\n+\tif (!pixmap(col) && !c.isBranch && !c.isCurrentBranch && !c.isTag && !c.isRef)\n+\t\treturn; // common case\n+\n+\tQPixmap* newPm = new QPixmap();\n+\n+\tif (c.isBranch || c.isCurrentBranch) {\n+\t\tQColor color(c.isCurrentBranch ? Qt::green : DARK_GREEN);\n+\t\taddTextPixmap(&newPm, c.branch, color, c.isCurrentBranch);\n \t}\n+\tif (c.isTag)\n+\t\taddTextPixmap(&newPm, c.tag, Qt::yellow);\n+\n+\tif (c.isRef)\n+\t\taddTextPixmap(&newPm, c.ref, PURPLE);\n+\n+\tif (!pixmap(col) || (newPm->rect() != pixmap(col)->rect()))\n+\t\tsetPixmap(col, *newPm);\n+\n+\tdelete newPm;\n+}\n+\n+void ListViewItem::addTextPixmap(QPixmap** pp, SCRef text, const\nQColor& color, bool bold) {\n+\n+\tQStringList sl = QStringList::split('\\n', text);\n+\tloopList(it, sl)\n+\t\tdoAddTextPixmap(pp, *it, color, bold);\n }\n\n-QPixmap* ListViewItem::doAddTextPixmap(SCRef text, const QColor&\ncolor, int col, bool bold) {\n+void ListViewItem::doAddTextPixmap(QPixmap** pp, SCRef text, const\nQColor& color, bool bold) {\n\n-\tconst QPixmap* oldPm = pixmap(col);\n  \tQFont fnt(listView()->font());\n \tif (bold)\n  \t\tfnt.setBold(true);\n\n  \tQFontMetrics fm(fnt);\n+\tQPixmap* pm = *pp;\n+\tint ofs = pm->isNull() ? 0 : pm->width() + 2;\n \tint spacing = 2;\n  \tint pw = fm.boundingRect(text).width() + 2 * (spacing + int(bold));\n  \tint ph = fm.height() + 1;\n-\tint ofs = oldPm ? oldPm->width() + 2 : 0;\n\n-\tQPixmap* pm = new QPixmap(ofs + pw, ph);\n+\tQPixmap* newPm = new QPixmap(ofs + pw, ph);\n\n  \tQPainter p;\n-\tp.begin(pm);\n-\tif (oldPm) {\n-\t\tpm->fill(isEvenLine ? EVEN_LINE_COL : ODD_LINE_COL);\n-\t\tp.drawPixmap(0, 0, *oldPm);\n+\tp.begin(newPm);\n+\tif (!pm->isNull()) {\n+\t\tnewPm->fill(isEvenLine ? EVEN_LINE_COL : ODD_LINE_COL);\n+\t\tp.drawPixmap(0, 0, *pm);\n \t}\n  \tp.setPen(Qt::black);\n  \tp.setBrush(color);\n@@ -676,7 +692,9 @@ QPixmap* ListViewItem::doAddTextPixmap(S\n  \tp.drawRect(ofs, 0, pw, ph);\n  \tp.drawText(ofs + spacing, fm.ascent(), text);\n \tp.end();\n-\treturn pm;\n+\n+\tdelete pm;\n+\t*pp = newPm;\n }\n\n  bool ListViewItem::changedFiles(SCRef c) {\n@@ -708,16 +726,6 @@ void ListViewItem::setupData(const Rev&\n \t}\n  \tsetText(LOG_COL + adj, c.shortLog());\n  \tsetText(AUTH_COL + adj, c.author());\n-\n-\tif (c.isBranch || c.isCurrentBranch) {\n-\t\tQColor color(c.isCurrentBranch ? Qt::green : DARK_GREEN);\n-\t\taddTextPixmap(c.branch, color, c.isCurrentBranch);\n-\t}\n-\tif (c.isTag)\n-\t\taddTextPixmap(c.tag, Qt::yellow);\n-\n-\tif (c.isRef)\n-\t\taddTextPixmap(c.ref, PURPLE);\n }\n\n  const QString ListViewItem::timeDiff(unsigned long secs) const {\n@@ -739,5 +747,3 @@ const QString ListViewItem::timeDiff(uns\n  \ttmp.append(QString::number(sec) + \"s\");\n  \treturn tmp;\n }\n-\n-\ndiff --git a/src/listview.h b/src/listview.h\nindex eafb7c2..b1f1011 100644\n--- a/src/listview.h\n+++ b/src/listview.h\n@@ -33,12 +33,11 @@ public:\n\n private:\n  \tvoid setupData(const Rev& c);\n-\tvoid paintGraphLane(QPainter* p, int type, int x1, int x2,\n-\t\t\t    const QColor& col, const QBrush& back);\n-\tvoid paintGraph(const Rev& c, QPainter *p,\n-\t\t\tconst QColorGroup& cg, int width);\n-\tvoid addTextPixmap(SCRef text, const QColor& color, bool bold = false);\n-\tQPixmap* doAddTextPixmap(SCRef text, const QColor& color, int col, bool bold);\n+\tvoid paintGraphLane(QPainter* p, int t, int x1, int x2, const\nQColor& c, const QBrush& b);\n+\tvoid paintGraph(const Rev& c, QPainter *p, const QColorGroup& cg, int width);\n+\tvoid paintTagMarks(int col, const Rev& c);\n+\tvoid addTextPixmap(QPixmap** pp, SCRef text, const QColor& color,\nbool bold = false);\n+\tvoid doAddTextPixmap(QPixmap** pp, SCRef text, const QColor& color,\nbool bold);\n \tconst QString timeDiff(unsigned long secs) const;\n \tbool changedFiles(SCRef c);\n\n-- \n1.4.3.GIT\n"},{"id":"298148","messageId":"200610242041.22230.Josef.Weidendorfer@gmx.de","threadId":"6038","inReplyTo":"e5bfff550610240947i30bc3fc0x49710e4cbb0f0556@mail.gmail.com","subject":"Re: [PATCH qgit] Change also tag marks when changing graph size","fromName":"Josef Weidendorfer","fromEmail":"josef.weidendorfer@gmx.de","sentAt":"2006-10-24T18:41:21Z","receivedAt":"2006-10-24T18:41:21Z","isPatch":true,"sender":{"key":"josef.weidendorfer@gmx.de","avatar":null},"body":"On Tuesday 24 October 2006 18:47, Marco Costalba wrote:\n> When changing graph size with CTRL+ and CTRL-\n> update also tag/branch marks.\n> \n> Also little cleanup.\n> ---\n> \n> Hi Josef,\n> \n>   please tell me if you are working on the same files, in this case I\n> will step back and wait you to finish your patch series and eventually\n> resubmit this one at the end.\n\nNo, that is fine. Currently, I have not much time.\nJust curious: What did you expect next in my patch series? :-)\n\nNow that everything is drawn directly, the question is what to do with\nthe new flexibility. E.g. we _could_ implement different\ngraph drawing algorithms next to the original qgit one,\ne.g. mimicking gitk.\nHowever, the highlighting functionality in gitk is really good, and I can\nimagine changing the background and color of lanes/commits according to\ne.g. ancestor/descendent from/to the nearest tag/branch head.\n\n"},{"id":"296597","messageId":"e5bfff550610241245r73b594ftf2cd39f4194b5411@mail.gmail.com","threadId":"6038","inReplyTo":"200610242041.22230.Josef.Weidendorfer@gmx.de","subject":"Re: [PATCH qgit] Change also tag marks when changing graph size","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2006-10-24T19:45:02Z","receivedAt":"2006-10-24T19:45:02Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"On 10/24/06, Josef Weidendorfer <Josef.Weidendorfer@gmx.de> wrote:\n> On Tuesday 24 October 2006 18:47, Marco Costalba wrote:\n> > When changing graph size with CTRL+ and CTRL-\n> > update also tag/branch marks.\n> >\n> > Also little cleanup.\n> > ---\n> >\n> > Hi Josef,\n> >\n> >   please tell me if you are working on the same files, in this case I\n> > will step back and wait you to finish your patch series and eventually\n> > resubmit this one at the end.\n>\n> No, that is fine. Currently, I have not much time.\n> Just curious: What did you expect next in my patch series? :-)\n>\n\nQuoting from your last e-mail:\n\"The new painting code regroups the drawing commands in\nmultiple switch-statements to prepare for far simpler code\nwith booleans for different elements, and not one type only.\"\n\nIndeed it's not clear to me what the above line means exactly, it just\nsmells like there is something more cooking. Sorry If I've\nmisunderstood.\n\n> Now that everything is drawn directly, the question is what to do with\n> the new flexibility. E.g. we _could_ implement different\n> graph drawing algorithms next to the original qgit one,\n> e.g. mimicking gitk.\n\nOne little secret of current algorithm is that it just needs to know\nthe \"state\" of previous revision graph to calculate the next one. (see\nGit::updateLanes() and lanes.cpp), it's a kind of a \"rasterized\" graph\ndrawing, i.e. line by line.\n\nI didn't studied gitk in deep but it seems a little bit less simpler.\nAnyway if you are interested it's for sure worth trying ;-)\n\n"},{"id":"298660","messageId":"200610250420.12324.Josef.Weidendorfer@gmx.de","threadId":"6038","inReplyTo":"e5bfff550610241245r73b594ftf2cd39f4194b5411@mail.gmail.com","subject":"Re: [PATCH qgit] Change also tag marks when changing graph size","fromName":"Josef Weidendorfer","fromEmail":"josef.weidendorfer@gmx.de","sentAt":"2006-10-25T02:20:12Z","receivedAt":"2006-10-25T02:20:12Z","isPatch":true,"sender":{"key":"josef.weidendorfer@gmx.de","avatar":null},"body":"On Tuesday 24 October 2006 21:45, Marco Costalba wrote:\n> Quoting from your last e-mail:\n> \"The new painting code regroups the drawing commands in\n> multiple switch-statements to prepare for far simpler code\n> with booleans for different elements, and not one type only.\"\n> \n> Indeed it's not clear to me what the above line means exactly, it just\n> smells like there is something more cooking.\n\nAh, yes ;-)\n\nCurrently, the drawing code knows how a full part of the graph\nshould be drawn, with circle, rects, lines.\nNow, with direct drawing, this \"knowledge\" can be moved to graph\nlayout time, which can generate info whether a circle or rect should\nbe drawn. Making drawing a little bit faster, and simpler.\n\nI am not sure if it is worth it, but this way, the drawing code could\nbe the same e.g. for different graph drawing algorithms (like gitk).\n\n> > Now that everything is drawn directly, the question is what to do with\n> > the new flexibility. E.g. we _could_ implement different\n> > graph drawing algorithms next to the original qgit one,\n> > e.g. mimicking gitk.\n> \n> One little secret of current algorithm is that it just needs to know\n> the \"state\" of previous revision graph to calculate the next one. (see\n> Git::updateLanes() and lanes.cpp), it's a kind of a \"rasterized\" graph\n> drawing, i.e. line by line.\n> \n> I didn't studied gitk in deep but it seems a little bit less simpler.\n> Anyway if you are interested it's for sure worth trying ;-)\n\nI will have a look.\n\nCurrent qgit layout gets really extremely wide e.g. with the kernel.\n\nSome ideas:\n* Put lanes to the right if possible\n* If a branch has no commit for more than e.g. 50 entries, it's better to\ndraw an arrow and get rid of the lane at all.\nBy clicking on an arrow head, we could rearrange the commit ordering\na little bit so that commits on the given branch move in a way that\nwe always see the context on this branch.\n* Collapsing parts of the graph into mega-commits, e.g.\n - straight commit lines\n - short topic branches forking from and merging into a branch\n\nJosef\n\n> \n>   Marco\n> \n"}]}