OSDN Git Service

Merge branch 'RNLAppearance' into develop
authoryuki <kimaira7@gmail.com>
Wed, 22 May 2013 01:54:36 +0000 (10:54 +0900)
committeryuki <kimaira7@gmail.com>
Wed, 22 May 2013 01:54:36 +0000 (10:54 +0900)
src/cx/fbn/nevernote/gui/RensoNoteListItem.java

index 7aa7ab0..294495b 100644 (file)
@@ -34,6 +34,7 @@ import com.trolltech.qt.gui.QMouseEvent;
 import com.trolltech.qt.gui.QPaintEvent;
 import com.trolltech.qt.gui.QPainter;
 import com.trolltech.qt.gui.QPalette;
+import com.trolltech.qt.gui.QPen;
 import com.trolltech.qt.gui.QTextOption;
 import com.trolltech.qt.gui.QWidget;
 
@@ -51,6 +52,7 @@ public class RensoNoteListItem extends QWidget{
        private final RensoNoteList parent;
        private final boolean isStared;
        private final int allPointSum;
+       private final QPalette palette;
        
        private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
        
@@ -85,9 +87,9 @@ public class RensoNoteListItem extends QWidget{
                String kaigyo = System.getProperty("line.separator");
                this.noteContent = this.noteContent.replaceAll(kaigyo, "");
                
-               QPalette p = new QPalette();
-               p.setColor(QPalette.ColorRole.Window, new QColor(255, 255, 255));
-               this.setPalette(p);
+               palette = new QPalette();
+               palette.setColor(QPalette.ColorRole.Window, new QColor(255, 255, 255));
+               this.setPalette(palette);
                this.setAutoFillBackground(true);
                this.setBackgroundRole(QPalette.ColorRole.Window);
        }
@@ -111,12 +113,6 @@ public class RensoNoteListItem extends QWidget{
                QFont normalFont = new QFont();
                normalFont.setPixelSize(12);
                
-               // 関連度
-               double ratio = (double)relationPoints / allPointSum;
-               int green = (int) (255 * (1.0 - ratio));
-               painter.setPen(new QColor(255, green, 0));
-               painter.setFont(relationFont);
-               painter.drawText(70, size().height() - 30, size().width() - 70, 30, Qt.AlignmentFlag.AlignRight.value(), String.valueOf((int)(ratio * 100)) + "%");
                // タイトル
                painter.setPen(QColor.black);
                painter.setFont(titleFont);
@@ -129,11 +125,34 @@ public class RensoNoteListItem extends QWidget{
                painter.setPen(QColor.black);
                painter.drawText(165, 23, size().width() - 165, 17, Qt.AlignmentFlag.AlignLeft.value(), tagNames);
                // ノート内容
+               QPen tmpPen = painter.pen();
+               painter.setPen(new QColor(100, 100, 100));
                QTextOption option = new QTextOption();
                option.setAlignment(Qt.AlignmentFlag.AlignLeft);
                option.setUseDesignMetrics(true);
-               painter.drawText(new QRectF(85, 40, width() - 85, 40), noteContent, option);
+               painter.drawText(new QRectF(85, 40, width() - 85, 45), noteContent, option);
+               painter.setPen(tmpPen);
                
+               // 関連度
+               double ratio = (double)relationPoints / allPointSum;
+               QColor relationColor;
+               if (ratio >= 0.8) {
+                       relationColor = new QColor(255, 0, 0);
+               } else if (ratio >= 0.5) {
+                       relationColor = new QColor(255, 100, 0);
+               } else {
+                       relationColor = new QColor(255, 200, 0);
+               }
+               painter.setFont(relationFont);
+               tmpPen = painter.pen();
+               painter.setPen(this.palette().color(QPalette.ColorRole.Window));
+               painter.drawText(size().width() - 70, size().height() - 33, 67, 33, Qt.AlignmentFlag.AlignRight.value(), String.valueOf((int)(ratio * 100)) + "%");
+               painter.drawText(size().width() - 70, size().height() - 33, 73, 33, Qt.AlignmentFlag.AlignRight.value(), String.valueOf((int)(ratio * 100)) + "%");
+               painter.drawText(70, size().height() - 36, size().width() - 70, 36, Qt.AlignmentFlag.AlignRight.value(), String.valueOf((int)(ratio * 100)) + "%");
+               painter.drawText(70, size().height() - 30, size().width() - 70, 30, Qt.AlignmentFlag.AlignRight.value(), String.valueOf((int)(ratio * 100)) + "%");
+               painter.setPen(relationColor);
+               painter.drawText(70, size().height() - 33, size().width() - 70, 33, Qt.AlignmentFlag.AlignRight.value(), String.valueOf((int)(ratio * 100)) + "%");             
+               painter.setPen(tmpPen);
                // サムネイル
                QImage img;
                String thumbnailName = Global.getFileManager().getResDirPath("thumbnail-" + noteGuid + ".png");
@@ -161,9 +180,8 @@ public class RensoNoteListItem extends QWidget{
        @Override
        protected void enterEvent(QEvent e){
                if (!parent.isContextMenuVisible()) {
-                       QPalette p = new QPalette();
-                       p.setColor(QPalette.ColorRole.Window, new QColor(225, 235, 255));
-                       this.setPalette(p);
+                       palette.setColor(QPalette.ColorRole.Window, new QColor(225, 235, 255));
+                       this.setPalette(palette);
                }
        }
        
@@ -176,16 +194,15 @@ public class RensoNoteListItem extends QWidget{
        
        @Override
        protected void mousePressEvent(QMouseEvent e) {
-               QPalette p = new QPalette();
-               p.setColor(QPalette.ColorRole.Window, new QColor(165, 175, 255));
-               this.setPalette(p);
+               
+               palette.setColor(QPalette.ColorRole.Window, new QColor(165, 175, 255));
+               this.setPalette(palette);
                
                super.mousePressEvent(e);
        }
        
        public void setDefaultBackground() {
-               QPalette p = new QPalette();
-               p.setColor(QPalette.ColorRole.Window, new QColor(255, 255, 255));
-               this.setPalette(p);
+               palette.setColor(QPalette.ColorRole.Window, new QColor(255, 255, 255));
+               this.setPalette(palette);
        }
 }