{"thread":{"id":"6003","subject":"[PATCH qgit 1/2] Directly draw lanes in ListView::paintCell()","startedAt":"2006-10-22T20:42:45Z","lastAt":"2006-10-22T22:35:25Z","messageCount":2,"participants":["Josef Weidendorfer","Marco Costalba"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"29669","messageId":"200610222242.45313.Josef.Weidendorfer@gmx.de","threadId":"6003","inReplyTo":null,"subject":"[PATCH qgit 1/2] Directly draw lanes in ListView::paintCell()","fromName":"Josef Weidendorfer","fromEmail":"josef.weidendorfer@gmx.de","sentAt":"2006-10-22T20:42:45Z","receivedAt":"2006-10-22T20:42:45Z","isPatch":true,"sender":{"key":"josef.weidendorfer@gmx.de","avatar":null},"body":"This gives much flexibility in contrast to previous fixed\npixmaps. E.g. lane symbols could overlap now, which was\nnot possible before.\n\nHowever, this patch does not change any drawing aside\nfrom fixing the ugly spaces in the lanes on commits with\ntag/branch labels, and shows the selection even in the\ngraph background (not really sure if this is wanted;\nhowever, easy to change).\n\nThis patch does not cleanup the old pixmap drawing; it even\nuses the width of one pixmap as global lane width.\nThe 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\nSigned-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>\n---\n\nHi Marco,\n\nthe change looks bigger than it really is because of the\npure rearrangement of the drawing code.\nI hope I used your indentation style.\n\nJosef\n\n src/listview.cpp |  184 +++++++++++++++++++++++++++++++++++++++++++++++-------\n src/listview.h   |    5 +-\n 2 files changed, 166 insertions(+), 23 deletions(-)\n\ndiff --git a/src/listview.cpp b/src/listview.cpp\nindex db19267..a947564 100644\n--- a/src/listview.cpp\n+++ b/src/listview.cpp\n@@ -405,24 +405,162 @@ void ListViewItem::setDiffTarget(bool b)\n \trepaint();\n }\n \n-void ListViewItem::paintGraph(const Rev& c, QPainter* p, const QColorGroup& cg, int width) {\n+/* Draw graph part for a lane\n+ */\n+void ListViewItem::paintGraphLane(QPainter* p, int type, int x1, int x2,\n+\t\t\t\t  const QColor& col, const QBrush& back) {\n+\n+        int h = height();\n+\tint r = (x2-x1)/3;\n+\n+#define P_CENTER  (x1+x2)/2, h/2\n+#define P_0       x2,        h/2\n+#define P_90      (x1+x2)/2, 0\n+#define P_180     x1,        h/2\n+#define P_270     (x1+x2)/2, h\n+#define R_CENTER  (x1+x2)/2-r, h/2-r, 2*r, 2*r\n+\n+        p->setPen(QPen(col, 2));\n+\n+\t// vertical line\n+\tswitch (type) {\n+\t\tcase ACTIVE:\n+\t\tcase NOT_ACTIVE:\n+\t\tcase MERGE_FORK:\n+\t\tcase MERGE_FORK_R:\n+\t\tcase MERGE_FORK_L:\n+\t\tcase JOIN:\n+\t\tcase JOIN_R:\n+\t\tcase JOIN_L:\n+\t\t\tp->drawLine(P_90, P_270);\n+\t\t\tbreak;\n+\t\tcase HEAD:\n+\t\tcase HEAD_R:\n+\t\tcase HEAD_L:\n+\t\tcase BRANCH:\n+\t\t\tp->drawLine(P_CENTER, P_270);\n+\t\t\tbreak;\n+\t\tcase TAIL:\n+\t\tcase TAIL_R:\n+\t\tcase TAIL_L:\n+\t\tcase INITIAL:\n+\t\tcase BOUNDARY:\n+\t\tcase BOUNDARY_C:\n+\t\tcase BOUNDARY_R:\n+\t\tcase BOUNDARY_L:\n+\t\t\tp->drawLine(P_90, P_CENTER);\n+\t\t\tbreak;\n+\t        default:\n+\t\t        break;\n+\t}\n+\n+\t// horizontal line\n+\tswitch (type) {\n+\t\tcase MERGE_FORK:\n+\t\tcase JOIN:\n+\t\tcase HEAD:\n+\t        case TAIL:\n+\t\tcase CROSS:\n+\t\tcase CROSS_EMPTY:\n+\t\tcase BOUNDARY_C:\n+\t\t\tp->drawLine(P_180, P_0);\n+\t\t\tbreak;\n+\t\tcase MERGE_FORK_R:\n+\t\tcase JOIN_R:\n+\t\tcase HEAD_R:\n+\t        case TAIL_R:\n+\t\tcase BOUNDARY_R:\n+\t\t\tp->drawLine(P_180, P_CENTER);\n+\t\t\tbreak;\n+\t\tcase MERGE_FORK_L:\n+\t\tcase JOIN_L:\n+\t\tcase HEAD_L:\n+\t        case TAIL_L:\n+\t\tcase BOUNDARY_L:\n+\t\t\tp->drawLine(P_CENTER, P_0);\n+\t\t\tbreak;\n+\t        default:\n+\t\t        break;\n+\t}\n+\n+\t// center symbol, e.g. rect or ellipse\n+\tswitch (type) {\n+\t\tcase ACTIVE:\n+\t\tcase INITIAL:\n+\t\tcase BRANCH:\n+\t\t\tp->setPen(Qt::NoPen);\n+\t\t\tp->setBrush(col);\n+\t\t\tp->drawEllipse(R_CENTER);\n+\t\t\tbreak;\n+\t\tcase MERGE_FORK:\n+\t\tcase MERGE_FORK_R:\n+\t\tcase MERGE_FORK_L:\n+\t\t\tp->setPen(Qt::NoPen);\n+\t\t\tp->setBrush(col);\n+\t\t\tp->drawRect(R_CENTER);\n+\t\t\tbreak;\n+\n+\t\tcase UNAPPLIED:\n+\t\t\t// Red minus sign\n+\t\t\tp->setPen(Qt::NoPen);\n+\t\t\tp->setBrush(red);\n+\t\t\tp->drawRect( (x1+x2)/2-r, h/2 - 1, 2*r, 2);\n+\t\t\tbreak;\n+\n+\t\tcase APPLIED:\n+\t\t\t// Green plus sign\n+\t\t\tp->setPen(Qt::NoPen);\n+\t\t\tp->setBrush(DARK_GREEN);\n+\t\t\tp->drawRect( (x1+x2)/2-r, h/2 - 1, 2*r, 2);\n+\t\t\tp->drawRect( (x1+x2)/2-1, h/2-r, 2, 2*r);\n+\t\t\tbreak;\n+\n+\t\tcase BOUNDARY:\n+\t\t\tp->setBrush(back);\n+\t\t\tp->drawEllipse(R_CENTER);\n+\t\t\tbreak;\n+\n+\t\tcase BOUNDARY_C:\n+\t\tcase BOUNDARY_R:\n+\t\tcase BOUNDARY_L:\n+\t\t\tp->setBrush(back);\n+\t\t\tp->drawRect(R_CENTER);\n+\t\t\tbreak;\n+\n+\t        default:\n+\t\t        break;\n+\t}\n+\n+#undef P_CENTER\n+#undef P_0\n+#undef P_90\n+#undef P_180\n+#undef P_270\n+#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+\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 \n-\t// Copied from QListViewItem::paintCell\n \tQListView* lv = listView();\n \tif (!lv)\n \t\treturn;\n \n-\tconst BackgroundMode bgmode = lv->viewport()->backgroundMode();\n-\tconst QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode(bgmode);\n+\tQColorGroup::ColorRole crole = QColorGroup::Base;\n+\tif ( isSelected() && lv->allColumnsShowFocus() )\n+\t    crole = QColorGroup::Highlight;\n \n-\tif (isSelected() && lv->allColumnsShowFocus())\n-\t\tp->fillRect(0, 0, width, height(), cg.brush(QColorGroup::Highlight));\n-\telse\n-\t\tp->fillRect(0, 0, width, height(), cg.brush(crole));\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-\tint pw = pms[0]->width();\n \tint mergeLane = -1;\n \tfor (uint i = 0; i < laneNum; i++)\n \t\tif (isMerge(lanes[i])) {\n@@ -430,26 +568,28 @@ void ListViewItem::paintGraph(const Rev&\n \t\t\tbreak;\n \t\t}\n \n-\tfor (uint i = 0; i < laneNum; i++) {\n+\tint laneWidth = pms[0]->width();\n+\tint x1 = 0, x2;\n+\tfor (uint i = 0; i < laneNum && x1 < width; i++, x1 = x2) {\n+\t        x2 = x1 + laneWidth;\n \n-\t\tint ln = lanes[i], idx;\n+\t\tint ln = lanes[i];\n \t\tif (ln == EMPTY)\n-\t\t\tcontinue;\n+\t\t    continue;\n \n+\t\tint type = ln;\n \t\tif (ln == CROSS)\n-\t\t\tidx = COLORS_NUM * (NOT_ACTIVE - 1);\n-\t\telse\n-\t\t\tidx = COLORS_NUM * (ln - 1);\n+\t\t    type = NOT_ACTIVE;\n \n \t\tint col = (   isHead(ln) || isTail(ln) || isJoin(ln)\n-\t\t           || ln == CROSS_EMPTY) ? mergeLane : i;\n+\t\t\t      || ln == CROSS_EMPTY) ? mergeLane : i;\n \n-\t\tidx += col % COLORS_NUM;\n-\t\tp->drawPixmap(i * pw, 0, *pms[idx]);\n-\t\tif (ln == CROSS) {\n-\t\t\tidx = COLORS_NUM * (CROSS - 1) + mergeLane % COLORS_NUM;\n-\t\t\tp->drawPixmap(i * pw, 0, *pms[idx]);\n-\t\t}\n+\t\tpaintGraphLane(p, type, x1, x2,\n+\t\t\t       colors[col % COLORS_NUM], back);\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}\n }\n \ndiff --git a/src/listview.h b/src/listview.h\nindex 8e78d71..7e52e9a 100644\n--- a/src/listview.h\n+++ b/src/listview.h\n@@ -33,7 +33,10 @@ public:\n \n private:\n \tvoid setupData(const Rev& c);\n-\tvoid paintGraph(const Rev& c, QPainter* p, const QColorGroup& cg, int width);\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 \tconst QString timeDiff(unsigned long secs) const;\n-- \n1.4.3.rc2.gf8ffb\n"},{"id":"29686","messageId":"e5bfff550610221535r60009371t46dfd5f7197ca0ad@mail.gmail.com","threadId":"6003","inReplyTo":"200610222242.45313.Josef.Weidendorfer@gmx.de","subject":"Re: [PATCH qgit 1/2] Directly draw lanes in ListView::paintCell()","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2006-10-22T22:35:25Z","receivedAt":"2006-10-22T22:35:25Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":">\n> Hi Marco,\n>\n> the change looks bigger than it really is because of the\n> pure rearrangement of the drawing code.\n> I hope I used your indentation style.\n>\n> Josef\n>\n\nHi Josef,\n\nThanks for the patches. Applied locally both, unfortunately I cannot push due to\na problem with hard disk: all my data is lost, so I don't have anymore\nthe ssh keys necessary to login at kernel.org\n\nI've already asked admin for help, but I think we have to wait few\ndays before to push patches again.\n\nAnyhow patches are very good, really, a breath of fresh air!\n\nMarco\n"}]}