@@ -558,19 +558,28 @@ class CardItemDelegate : public QStyledItemDelegate {
558558 const QModelIndex &index) const override {
559559 painter->save ();
560560 const bool selected = option.state & QStyle::State_Selected;
561+ const bool hovered = option.state & QStyle::State_MouseOver;
562+ const QPalette &palette = option.palette ;
561563
562564 // Card background
563565 painter->setRenderHint (QPainter::Antialiasing);
564566 QRectF cardRect = option.rect .adjusted (4 , 4 , -4 , -4 );
565- QColor bgColor = selected ? QColor (" #e0f7fa" ) : QColor (" #ffffff" );
567+ QColor bgColor;
568+ if (selected) {
569+ bgColor = palette.color (QPalette::Highlight);
570+ } else if (hovered) {
571+ bgColor = palette.color (QPalette::AlternateBase);
572+ } else {
573+ bgColor = palette.color (QPalette::Base);
574+ }
566575 painter->setBrush (bgColor);
567576 painter->setPen (Qt::NoPen);
568- painter->drawRoundedRect (cardRect, 10 , 10 );
577+ painter->drawRoundedRect (cardRect, 0 , 0 );
569578
570579 // Picture space (left side)
571580 qint64 x = cardRect.left () + 10 ;
572- qint64 y = cardRect.top () + 10 ;
573- QRect imageRect = QRect (x, y, 320 , 240 );
581+ qint64 y = cardRect.top () + 40 ;
582+ QRect imageRect = QRect (x, y, 160 , 120 );
574583 painter->setBrush (QColor (" #cccccc" ));
575584 QPixmap cover = index.data (Qt::UserRole + 4 ).value <QPixmap>();
576585
@@ -591,7 +600,7 @@ class CardItemDelegate : public QStyledItemDelegate {
591600 painter->setPen (Qt::black);
592601
593602 QString title = index.data (Qt::DisplayRole).toString ();
594- point.setX (textX );
603+ point.setX (imageRect. left () );
595604 point.setY (textY + 15 );
596605 painter->drawText (point, title);
597606
@@ -601,7 +610,8 @@ class CardItemDelegate : public QStyledItemDelegate {
601610
602611 qint64 typeId = index.data (Qt::UserRole + 2 ).toInt ();
603612 QString type = StaticData ().getType ()[typeId];
604- point.setY (textY + 50 );
613+ point.setX (textX);
614+ point.setY (textY + 60 );
605615 QString typeText = QString (" Type: %1" ).arg (type);
606616 painter->drawText (point, typeText);
607617
@@ -611,34 +621,34 @@ class CardItemDelegate : public QStyledItemDelegate {
611621 if (authors.size () > 100 ) {
612622 authors = " Various" ;
613623 }
614- point.setY (textY + 35 );
624+ point.setY (textY + 45 );
615625 QString authorsText = QString (" By: %1" ).arg (authors);
616626 painter->drawText (point, authorsText);
617627
618628 qint64 classId = index.data (Qt::UserRole + 7 ).toInt ();
619629 QString class_ = StaticData ().getClass ()[classId];
620- point.setY (textY + 80 );
630+ point.setY (textY + 90 );
621631 QString classText = QString (" class: %1" ).arg (class_);
622632 painter->drawText (point, classText);
623633
624634 qint64 difficultyId = index.data (Qt::UserRole + 8 ).toInt ();
625635 QString difficulty = StaticData ().getDifficulty ()[difficultyId];
626- point.setY (textY + 110 );
636+ point.setY (textY + 120 );
627637 QString difficultyText = QString (" Difficulty: %1" ).arg (difficulty);
628638 painter->drawText (point, difficultyText);
629639
630640 qint64 durationId = index.data (Qt::UserRole + 9 ).toInt ();
631641 QString duration = StaticData ().getDuration ()[durationId];
632- point.setY (textY + 95 );
642+ point.setY (textY + 105 );
633643 QString durationText = QString (" Duration: %1" ).arg (duration);
634644 painter->drawText (point, durationText);
635645 } else {
636646 QString shortBody = index.data (Qt::UserRole + 5 ).toString ();
637- point.setY (textY + 80 );
647+ point.setY (textY + 90 );
638648 painter->drawText (point, shortBody);
639649 }
640650 QString release = index.data (Qt::UserRole + 3 ).toString ();
641- point.setY (textY + 65 );
651+ point.setY (textY + 75 );
642652 QString releaseText = QString (" Released: %1" ).arg (release);
643653 painter->drawText (point, releaseText);
644654
@@ -648,7 +658,7 @@ class CardItemDelegate : public QStyledItemDelegate {
648658
649659 QSize sizeHint (
650660 const QStyleOptionViewItem&, const QModelIndex&) const override {
651- return QSize (600 , 300 );
661+ return QSize (600 , 180 );
652662 }
653663};
654664
0 commit comments