OSDN Git Service

fixing selected
authorsuma <devnull@localhost>
Thu, 4 Dec 2008 12:54:21 +0000 (21:54 +0900)
committersuma <devnull@localhost>
Thu, 4 Dec 2008 12:54:21 +0000 (21:54 +0900)
src/control/color.h
src/control/standard/hexview.cpp
src/control/standard/hexview.h
src/control/view.cpp

index 9dcebac..9b4e308 100644 (file)
@@ -5,8 +5,8 @@ namespace Color {
        enum color {
                Background = 0,
                Text,
-               HiBackground,   // hilighted
-               HiSelText,
+               SelBackground,  // hilighted
+               SelText,
                ColorCount,
        };
 }
index e51741a..fa51cd3 100644 (file)
@@ -15,12 +15,14 @@ namespace Standard {
 // Config
 HexConfig::HexConfig()
        : Margin(10, 10, 10, 10)
-       , ByteMargin(0, 4, 5, 1)
-       , Font("times", 24)
+       , ByteMargin(0, 2, 2, 1)
+       , Font("Monaco", 13)
        , FontMetrics(Font)
 {
-       Colors[Color::Background] = QColor(255,0,0);
-       Colors[Color::Text] = QColor(0,0,255);
+       Colors[Color::Background] = QColor(255,255,255);
+       Colors[Color::Text] = QColor(0,0,0);
+       Colors[Color::SelBackground] = QColor(0xCC,0xCC,0);
+       Colors[Color::SelText] = QColor(0,0xCC,0xCC);
 
        for (int i = 1; i < Num; i++) {
                Spaces[i] = FontMetrics.maxWidth();
@@ -95,8 +97,7 @@ void HexView::refreshPixmap(int)
        QPainter painter(&pix_);
        //painter.initFrom(this);
 
-       painter.drawText(20, 20, QString("abcdefg"));
-
+       //painter.drawText(220, 20, QString("abcdefg"));
 
        if (!doc_->length()) {
                // draw Empty Background only
@@ -116,8 +117,8 @@ void HexView::refreshPixmap(int)
        bool selected = false;
        quint64 sb = 0, se = 0;
        if (cur_->Selected) {
-               sb = max(cur_->SelBegin, cur_->SelEnd);
-               se = min(cur_->SelBegin, cur_->SelEnd);
+               sb = min(cur_->SelBegin, cur_->SelEnd);
+               se = max(cur_->SelBegin, cur_->SelEnd);
                if (top <= se) {
                        const quint64 vpos_end = max(top + (16ULL * yCount), top + size);
                        if (sb <= vpos_end) {
@@ -139,37 +140,42 @@ void HexView::refreshPixmap(int)
        // draw
        DCIList::iterator itr = dcolors_.begin(), end = dcolors_.end();
        QBrush br;
-       for (int i = 0, j = 0, x = 0, cont = 0; itr != end; i++) {
-               if (!x) {
+       for (int i = 0, j = 0, m = 0, cont = 0; itr != end;) {
+               if (m == 0) {
                        br = QBrush(itr->Colors[Color::Background]);
-                       x = itr->Length;
+                       m = itr->Length;
 
                        // Set color
                        painter.setBackground(br);
                        painter.setPen(itr->Colors[Color::Text]);
-               } else {
-                       ++itr;
                }
 
                // Continuous size
-               cont = min(x, 16 - j);
+               cont = min(m, HexConfig::Num - j);
+               printf("m:%d j:%d cont:%d\n", m, j, cont);
                if (2 <= cont) {
                        // Draw background
-                       painter.fillRect(config_.x(j), yt, config_.byteEnd(j+cont), yt + config_.byteHeight(), br);
+                       Q_ASSERT(0 <= j && j < HexConfig::Num);
+                       Q_ASSERT(0 <= j+cont-1 && j+cont-1 < HexConfig::Num);
+                       painter.fillRect(config_.x(j), yt, config_.byteEnd(j+cont-1), yt + config_.byteHeight(), br);
+               } else if (j < 15) { //(j < HexConfig::Num - 1) {
+                       Q_ASSERT(0 <= j && j < HexConfig::Num);
+                       Q_ASSERT(0 <= j+1 && j+1 < HexConfig::Num);
+                       painter.fillRect(config_.x(j), yt, config_.X(j+1), yt + config_.byteHeight(), br);
                }
 
                // Draw
-               for (int k = 0; i < cont; i++) {
-                       QString h,l;
-                       byteToHex(buff_[i], h, l);
-                       painter.drawText(config_.x(j), y, h);
-                       painter.drawText(config_.x(j) + config_.fontMetrics().maxWidth(), y, l);
+               for (int k = 0; k < cont; k++, i++, j++) {
+                       QString hex;
+                       byteToHex(buff_[i], hex);
+                       painter.drawText(config_.x(j), y, hex);
                }
 
-               x -= cont;
-               x += cont;
-               j += cont & 0xF;
-
+               m -= cont;
+               j = j & 0xF;
+               if (m == 0) {
+                       ++itr;
+               }
                if (j == 0) {
                        y += config_.byteHeight();
                        yt += config_.byteHeight();
@@ -179,7 +185,7 @@ void HexView::refreshPixmap(int)
        update();
 }
 
-void HexView::byteToHex(uchar c, QString &h, QString &l)
+void HexView::byteToHex(uchar c, QString &h)
 {
        const uchar H = (c >> 4) & 0xF;
        if (H <= 9) {
@@ -189,9 +195,9 @@ void HexView::byteToHex(uchar c, QString &h, QString &l)
        }
        const uchar L = c & 0xF;
        if (L <= 9) {
-               = '0' + L;
+               h += '0' + L;
        } else {
-               = 'A' + L;
+               h += 'A' + L;
        }
 }
 
index b8d20af..63408c1 100644 (file)
@@ -64,6 +64,11 @@ namespace Standard {
                        Q_ASSERT(0 <= i && i < Num);
                        return x_[i];
                }
+               inline int X(int i) const
+               {
+                       Q_ASSERT(0 <= i && i < Num);
+                       return x_[i] - ByteMargin.left();
+               }
                int toPos(int x);       // -1, 0..31, 32:: 32 + 2 = 34
                int toLine(int y);      // [0, N]
                void calculate();
@@ -87,7 +92,7 @@ namespace Standard {
                void mouseMoveEvent(QMouseEvent*);
                void mouseReleaseEvent(QMouseEvent*);
 
-               void byteToHex(uchar c, QString &h, QString &l);
+               void byteToHex(uchar c, QString &h);
 
        protected:
                // Main components
index 74c58c8..e6f5c0b 100644 (file)
@@ -74,12 +74,14 @@ void View::getDrawColors(const DrawInfo &di, DCIList &ci, QColor *defColors)
                        // check colors
                        qint64 diff = sb - index;
                        qint64 left = se - index;
+                       printf("sb: %d, se: %d\n", sb, se);
                        int i = 0;
                        QColor *last = NULL;
                        for (HCIList::iterator itr = hcolors_.begin(), end = hcolors_.end(); i < size; i++, index++, diff--, left--) {
                                bool sel = sb <= index && index <= se;
                                int x = sel ? 2 : 0;
                                if (itr == end || i < itr->Index || itr->Index + itr->Length < i) {
+                                       printf("i: %d sel: %d\n", i, sel);
                                        // out of itr
                                        if (last == defColors + x) {
                                                // continues same color