Mercurial > hg > easyhg
comparison src/changesetitem.cpp @ 600:641ccce7c771
Avoid messing with font size when zooming, let it zoom naturally; don't delete detail item when removing it, just let it wait to be shown again (and do delete it when deleting main item)
author | Chris Cannam |
---|---|
date | Fri, 11 May 2012 17:44:33 +0100 |
parents | 1e76d1009167 |
children | ae67ea0af696 |
comparison
equal
deleted
inserted
replaced
599:538b6ae5c272 | 600:641ccce7c771 |
---|---|
34 #include <QClipboard> | 34 #include <QClipboard> |
35 | 35 |
36 QImage *ChangesetItem::m_star = 0; | 36 QImage *ChangesetItem::m_star = 0; |
37 | 37 |
38 ChangesetItem::ChangesetItem(Changeset *cs) : | 38 ChangesetItem::ChangesetItem(Changeset *cs) : |
39 m_changeset(cs), m_detail(0), | 39 m_changeset(cs), m_detail(0), m_detailVisible(false), |
40 m_showBranch(false), m_column(0), m_row(0), m_wide(false), | 40 m_showBranch(false), m_column(0), m_row(0), m_wide(false), |
41 m_current(false), m_closing(false), m_new(false), m_searchMatches(false) | 41 m_current(false), m_closing(false), m_new(false), m_searchMatches(false) |
42 { | 42 { |
43 m_font = QFont(); | 43 m_font = QFont(); |
44 m_font.setPixelSize(11); | 44 m_font.setPixelSize(11); |
47 setCursor(Qt::ArrowCursor); | 47 setCursor(Qt::ArrowCursor); |
48 | 48 |
49 if (!m_star) m_star = new QImage(":images/star.png"); | 49 if (!m_star) m_star = new QImage(":images/star.png"); |
50 } | 50 } |
51 | 51 |
52 ChangesetItem::~ChangesetItem() | |
53 { | |
54 if (m_detail && !m_detailVisible) delete m_detail; | |
55 } | |
56 | |
52 QString | 57 QString |
53 ChangesetItem::getId() | 58 ChangesetItem::getId() |
54 { | 59 { |
55 return m_changeset->id(); | 60 return m_changeset->id(); |
56 } | 61 } |
64 } | 69 } |
65 | 70 |
66 void | 71 void |
67 ChangesetItem::showDetail() | 72 ChangesetItem::showDetail() |
68 { | 73 { |
69 if (m_detail) return; | 74 if (m_detailVisible) return; |
70 m_detail = new ChangesetDetailItem(m_changeset); | 75 if (!m_detail) { |
71 m_detail->setZValue(zValue() + 1); | 76 m_detail = new ChangesetDetailItem(m_changeset); |
77 m_detail->setZValue(zValue() + 1); | |
78 } | |
72 scene()->addItem(m_detail); | 79 scene()->addItem(m_detail); |
73 int w = 100; | 80 int w = 100; |
74 if (m_wide) w = 180; | 81 if (m_wide) w = 180; |
75 if (isMerge() || isClosingCommit()) w = 60; | 82 if (isMerge() || isClosingCommit()) w = 60; |
76 int h = 80; | 83 int h = 80; |
77 // m_detail->moveBy(x() - (m_detail->boundingRect().width() - 50) / 2, | 84 m_detail->setPos(x() + (w + 50) / 2 + 10 + 0.5, |
78 // y() + 60); | |
79 m_detail->moveBy(x() + (w + 50) / 2 + 10 + 0.5, | |
80 y() - (m_detail->boundingRect().height() - h) / 3 + 0.5); | 85 y() - (m_detail->boundingRect().height() - h) / 3 + 0.5); |
86 m_detailVisible = true; | |
81 emit detailShown(); | 87 emit detailShown(); |
82 } | 88 } |
83 | 89 |
84 void | 90 void |
85 ChangesetItem::hideDetail() | 91 ChangesetItem::hideDetail() |
86 { | 92 { |
87 if (!m_detail) return; | 93 if (!m_detailVisible) return; |
88 scene()->removeItem(m_detail); | 94 scene()->removeItem(m_detail); |
89 delete m_detail; | 95 m_detailVisible = false; |
90 m_detail = 0; | |
91 emit detailHidden(); | 96 emit detailHidden(); |
92 } | 97 } |
93 | 98 |
94 bool | 99 bool |
95 ChangesetItem::matchSearchText(QString text) | 100 ChangesetItem::matchSearchText(QString text) |
110 void | 115 void |
111 ChangesetItem::mousePressEvent(QGraphicsSceneMouseEvent *e) | 116 ChangesetItem::mousePressEvent(QGraphicsSceneMouseEvent *e) |
112 { | 117 { |
113 DEBUG << "ChangesetItem::mousePressEvent" << endl; | 118 DEBUG << "ChangesetItem::mousePressEvent" << endl; |
114 if (e->button() == Qt::LeftButton) { | 119 if (e->button() == Qt::LeftButton) { |
115 if (m_detail) { | 120 if (m_detailVisible) { |
116 hideDetail(); | 121 hideDetail(); |
117 } else { | 122 } else { |
118 showDetail(); | 123 showDetail(); |
119 } | 124 } |
120 } | 125 } |
301 | 306 |
302 QFont f(m_font); | 307 QFont f(m_font); |
303 | 308 |
304 QTransform t = paint->worldTransform(); | 309 QTransform t = paint->worldTransform(); |
305 float scale = std::min(t.m11(), t.m22()); | 310 float scale = std::min(t.m11(), t.m22()); |
306 if (scale > 1.0) { | |
307 int ps = int((f.pixelSize() / scale) + 0.5); | |
308 if (ps < 8) ps = 8; | |
309 f.setPixelSize(ps); | |
310 } | |
311 | 311 |
312 bool showText = (scale >= 0.2); | 312 bool showText = (scale >= 0.2); |
313 bool showProperLines = (scale >= 0.1); | 313 bool showProperLines = (scale >= 0.1); |
314 | 314 |
315 if (m_searchText != "") { | 315 if (m_searchText != "") { |