[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    [Panel-devel] Kickoff menu items
From:       Aurélien Gâteau <aurelien.gateau () free ! fr>
Date:       2007-11-29 21:31:00
Message-ID: finb2k$6qa$1 () ger ! gmane ! org
[Download RAW message or body]

Hello,

I have been playing with Kickoff menu items lately. More precisely with the
way selected items are drawn. You can have a look at the result here:

http://img502.imageshack.us/img502/9761/kickofffullwidthselectivn3.png

and here:

http://img110.imageshack.us/img110/9177/kickoffblingpp4.png

I made quite a few changes which I will try to list here:
- Changed the selection to fill the full width of the view. It looks more
like a menu this way and it visually connects the item with its expand
arrow on the right if there is any.

- Icons aren't painted a bit transparent anymore. I thought it looked a bit
too washed out. A nicer effect can probably be achieved by highlighting the
selected item, the same way it's done in Konqueror and Dolphin.

- I thought the title looked strange when it was vertically aligned on top
of the item rect, so I centered it instead, and moved the subtitle on its
right (in a crude way, since they use the same font).

Attached patch implements this. You will notice a "#ifdef BLING" in it.
Enabling it paints selecteditems with the gradient you can see in the
second screenshot.
The patch is quite hackish, I just want to know if you think it's a good
idea. In this case I'll clean it up.

Aurélien

["kickoff_selected_items.diff" (text/x-diff)]

Index: ui/flipscrollview.cpp
===================================================================
--- ui/flipscrollview.cpp	(révision 742711)
+++ ui/flipscrollview.cpp	(copie de travail)
@@ -533,7 +533,7 @@
             QRect triRect = option.rect;
             QPainterPath tPath = d->trianglePath();
             triRect.setLeft(triRect.right() - ItemDelegate::ITEM_RIGHT_MARGIN);
-            painter.translate(triRect.center().x(), triRect.y() + \
(tPath.boundingRect().height() / 2)  + 3); +            \
painter.translate(triRect.center().x(), triRect.y() + (triRect.height() - \
tPath.boundingRect().height()) / 2 + 5);  painter.rotate(180);
             painter.drawPath(tPath);
             painter.resetTransform();
Index: ui/itemdelegate.cpp
===================================================================
--- ui/itemdelegate.cpp	(révision 742711)
+++ ui/itemdelegate.cpp	(copie de travail)
@@ -47,7 +47,8 @@
 {
     const bool hover = option.state & \
(QStyle::State_Selected|QStyle::State_MouseOver|QStyle::State_HasFocus);  QRect \
                contentRect = option.rect;
-    contentRect.setBottom(contentRect.bottom() - 1);
+    contentRect.adjust(3, 0, 0, -1);
+    //contentRect.setBottom(contentRect.bottom() - 1);
     QRect decorationRect = QStyle::alignedRect(option.direction,
                                                option.decorationPosition == \
QStyleOptionViewItem::Left ? Qt::AlignLeft : Qt::AlignRight,  option.decorationSize,
@@ -69,6 +70,14 @@
                                          textSize,
                                          contentRect.adjusted(0, 2, 0, 0));
     QString titleText = index.data(Qt::DisplayRole).value<QString>();
+    if (hover) {
+        QString subTitleText = index.data(SubTitleRole).value<QString>();
+        if (!subTitleText.isEmpty()) {
+            titleText += " (" + subTitleText + ")";
+        }
+    }
+    QRect titleRect = textRect;
+#if 0
     QString subTitleText = index.data(SubTitleRole).value<QString>();
 
     QRect titleRect = textRect;
@@ -81,13 +90,14 @@
     QRect subTitleRect = titleRect;
     subTitleRect.translate(0, subTitleRect.height());
     QFont subTitleFont = fontForSubTitle(option.font);
-
+#endif
     QFont titleFont(option.font);
 
     if (hover) {
         painter->save();
         painter->setPen(Qt::NoPen);
         QColor backgroundColor = option.palette.color(QPalette::Highlight);
+        #if 0
         QFontMetrics titleMetrics(titleFont);
         QFontMetrics subTitleMetrics(subTitleFont);
         QRect textAreaRect = contentRect;
@@ -98,22 +108,40 @@
         backgroundColor.setAlphaF(0.5);
         painter->setBrush(QBrush(backgroundColor));
         painter->drawPath(roundedRectangle(textAreaRect, 5));
+        #endif
+        painter->setOpacity(0.5);
+        painter->setBrush(QBrush(backgroundColor));
+        painter->drawPath(roundedRectangle(option.rect, 5));
+
+        //#define BLING
+        #ifdef BLING
+        QLinearGradient gradient;
+        gradient.setStart(option.rect.topLeft());
+        gradient.setFinalStop(option.rect.bottomLeft());
+        gradient.setColorAt(0, QColor::fromRgbF(1, 1, 1, 0.8));
+        gradient.setColorAt(0.399, QColor::fromRgbF(1, 1, 1, 0.3));
+        gradient.setColorAt(0.4, QColor::fromRgbF(1, 1, 1, 0));
+        gradient.setColorAt(1, QColor::fromRgbF(1, 1, 1, 0.3));
+        painter->setBrush(gradient);
+        painter->setOpacity(1);
+        painter->drawPath(roundedRectangle(option.rect.adjusted(1, 1, -1, -1), 5));
+        #endif
         painter->restore();
     }
 
     // draw icon
     QIcon decorationIcon = index.data(Qt::DecorationRole).value<QIcon>();
 
-    if (!hover) {
+    /*if (!hover) {
         painter->save();
         painter->setOpacity(0.7);
-    }
+    }*/
 
     decorationIcon.paint(painter, decorationRect, option.decorationAlignment);
 
-    if (!hover) {
+    /*if (!hover) {
         painter->restore();
-    }
+    }*/
 
     painter->save();
 
@@ -121,11 +149,13 @@
     painter->setFont(titleFont);
     painter->drawText(titleRect, Qt::AlignLeft|Qt::AlignVCenter, titleText);
 
+#if 0
     if (hover) {
         // draw sub-title
         painter->setFont(subTitleFont);
         painter->drawText(subTitleRect, Qt::AlignLeft|Qt::AlignVCenter, \
subTitleText);  }
+#endif
 
     painter->restore();
 
@@ -134,9 +164,12 @@
         painter->save();
 
         QFontMetrics titleMetrics(option.font);
+        #if 0
         QFontMetrics subTitleMetrics(subTitleFont);
 
         qreal actualTextWidth = qMax(titleMetrics.width(titleText), \
subTitleMetrics.width(subTitleText)); +        #endif
+        qreal actualTextWidth = titleMetrics.width(titleText);
 
         QSize spaceSize = option.rect.size();
         //kDebug() << "space size is" << spaceSize.rwidth() << "and we're going to \
lop off" @@ -209,7 +242,7 @@
     subTitleFont.setPointSize(qMax(subTitleFont.pointSize() - 2,
                                    \
KGlobalSettings::smallestReadableFont().pointSize()));  QFontMetrics \
                subMetrics(subTitleFont);
-    size.setHeight(qMax(option.decorationSize.height(), qMax(size.height(), \
metrics.height() + subMetrics.ascent()) + 3)); +    \
size.setHeight(qMax(option.decorationSize.height(), qMax(size.height(), \
metrics.height() + subMetrics.ascent()) + 3 ));  //    kDebug() << "size hint is" << \
size << (metrics.height() + subMetrics.ascent());  
     return size;



_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic