]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Get rid of using deprecated Q3Button::drawButton() interface. Now the URL navigator...
authorPeter Penz <peter.penz19@gmail.com>
Fri, 24 Nov 2006 18:34:52 +0000 (18:34 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 24 Nov 2006 18:34:52 +0000 (18:34 +0000)
svn path=/trunk/playground/utils/dolphin/; revision=607457

src/bookmarkselector.cpp
src/bookmarkselector.h
src/urlnavigatorbutton.cpp
src/urlnavigatorbutton.h

index 8cd2917dc149797aefc06413c91db67cb2b9c443..73e063fdaa66dee97c5c61452baa1a16bce81a11 100644 (file)
@@ -106,15 +106,23 @@ KBookmark BookmarkSelector::selectedBookmark() const
     return DolphinSettings::instance().bookmark(m_selectedIndex);
 }
 
-void BookmarkSelector::drawButton(QPainter* painter)
+QSize BookmarkSelector::sizeHint() const
 {
+    const int height = UrlButton::sizeHint().height();
+    return QSize(height, height);
+}
+
+void BookmarkSelector::paintEvent(QPaintEvent* event)
+{
+    QPainter painter(this);
+
     const int buttonWidth  = width();
     const int buttonHeight = height();
 
     QColor backgroundColor;
     QColor foregroundColor;
     const bool isHighlighted = isDisplayHintEnabled(EnteredHint) ||
-        isDisplayHintEnabled(DraggedHint);
+                               isDisplayHintEnabled(DraggedHint);
     if (isHighlighted) {
         backgroundColor = KGlobalSettings::highlightColor();
         foregroundColor = KGlobalSettings::highlightedTextColor();
@@ -140,21 +148,19 @@ void BookmarkSelector::drawButton(QPainter* painter)
     if (!(isDisplayHintEnabled(ActivatedHint) && isActive) && !isHighlighted) {
         // dimm the foreground color by mixing it with the background
         foregroundColor = mixColors(foregroundColor, backgroundColor);
-        painter->setPen(foregroundColor);
+        painter.setPen(foregroundColor);
     }
 
     // draw button backround
-    painter->setPen(Qt::NoPen);
-    painter->setBrush(backgroundColor);
-    painter->drawRect(0, 0, buttonWidth, buttonHeight);
+    painter.setPen(Qt::NoPen);
+    painter.setBrush(backgroundColor);
+    painter.drawRect(0, 0, buttonWidth, buttonHeight);
 
     // draw icon
-    const QPixmap* icon = pixmap();
-    if (icon != 0) {
-        const int x = (buttonWidth - icon->width()) / 2;
-        const int y = (buttonHeight - icon->height()) / 2;
-        painter->drawPixmap(x, y, *icon);
-    }
+    const QPixmap pixmap = icon().pixmap();
+    const int x = (buttonWidth -  pixmap.width()) / 2;
+    const int y = (buttonHeight - pixmap.height()) / 2;
+    painter.drawPixmap(x, y, pixmap);
 }
 
 void BookmarkSelector::slotBookmarkActivated(int index)
index 3a967b5dc4ee2fbd8cd4aca3a769da427ed35555..43c6618150b0c6f9293e7a6f4e9cdbc0cd05bbdd 100644 (file)
@@ -70,6 +70,9 @@ public:
     /** Returns the selected bookmark. */
     KBookmark selectedBookmark() const;
 
+    /** @see QWidget::sizeHint() */
+    virtual QSize sizeHint() const;
+
 signals:
     /**
      * Is send when a bookmark has been activated by the user.
@@ -82,7 +85,7 @@ protected:
      * Draws the icon of the selected Url as content of the Url
      * selector.
      */
-    virtual void drawButton(QPainter* painter);
+    virtual void paintEvent(QPaintEvent* event);
 
 private slots:
     /**
index 811a11b89246035076df2c900b866135e5064d0b..fab2b81e97d6a66973f69a8743d3f6d86c146688 100644 (file)
@@ -89,13 +89,15 @@ void UrlNavigatorButton::setIndex(int index)
     update();
 }
 
-int UrlNavigatorButton::index() const
+QSize UrlNavigatorButton::sizeHint() const
 {
-    return m_index;
+    const int width = fontMetrics().width(text()) + (arrowWidth() * 4);
+    return QSize(width, UrlButton::sizeHint().height());
 }
 
-void UrlNavigatorButton::drawButton(QPainter* painter)
+void UrlNavigatorButton::paintEvent(QPaintEvent* event)
 {
+    QPainter painter(this);
     const int buttonWidth  = width();
     const int buttonHeight = height();
 
@@ -127,18 +129,18 @@ void UrlNavigatorButton::drawButton(QPainter* painter)
     }
 
     // draw button background
-    painter->setPen(Qt::NoPen);
-    painter->setBrush(backgroundColor);
-    painter->drawRect(0, 0, buttonWidth, buttonHeight);
+    painter.setPen(Qt::NoPen);
+    painter.setBrush(backgroundColor);
+    painter.drawRect(0, 0, buttonWidth, buttonHeight);
 
     int textWidth = buttonWidth;
     if (isDisplayHintEnabled(ActivatedHint) && isActive || isHighlighted) {
-        painter->setPen(foregroundColor);
+        painter.setPen(foregroundColor);
     }
     else {
         // dimm the foreground color by mixing it with the background
         foregroundColor = mixColors(foregroundColor, backgroundColor);
-        painter->setPen(foregroundColor);
+        painter.setPen(foregroundColor);
     }
 
     if (!isDisplayHintEnabled(ActivatedHint)) {
@@ -150,8 +152,8 @@ void UrlNavigatorButton::drawButton(QPainter* painter)
         const int startTopY = middleY - (width - 1);
         const int startBottomY = middleY + (width - 1);
         for (int i = 0; i < width; ++i) {
-            painter->drawLine(startX, startTopY + i, startX + i, startTopY + i);
-            painter->drawLine(startX, startBottomY - i, startX + i, startBottomY - i);
+            painter.drawLine(startX, startTopY + i, startX + i, startTopY + i);
+            painter.drawLine(startX, startBottomY - i, startX + i, startBottomY - i);
         }
 
         textWidth = startX - border;
@@ -159,7 +161,7 @@ void UrlNavigatorButton::drawButton(QPainter* painter)
 
     const bool clipped = isTextClipped();
     const int align = clipped ? Qt::AlignVCenter : Qt::AlignCenter;
-    painter->drawText(QRect(0, 0, textWidth, buttonHeight), align, text());
+    painter.drawText(QRect(0, 0, textWidth, buttonHeight), align, text());
 
     if (clipped) {
         // Blend the right area of the text with the background, as the
@@ -172,9 +174,9 @@ void UrlNavigatorButton::drawButton(QPainter* painter)
         const int greenInc = (foregroundColor.green() - backgroundColor.green()) / blendSteps;
         const int blueInc  = (foregroundColor.blue()  - backgroundColor.blue())  / blendSteps;
         for (int i = 0; i < blendSteps; ++i) {
-            painter->setClipRect(QRect(textWidth - i, 0, 1, buttonHeight));
-            painter->setPen(blendColor);
-            painter->drawText(QRect(0, 0, textWidth, buttonHeight), align, text());
+            painter.setClipRect(QRect(textWidth - i, 0, 1, buttonHeight));
+            painter.setPen(blendColor);
+            painter.drawText(QRect(0, 0, textWidth, buttonHeight), align, text());
 
             blendColor.setRgb(blendColor.red()   + redInc,
                               blendColor.green() + greenInc,
index 44671fe2ddbe4e4d0301dd948bc8bbd99844b19d..5ce54b31d41c07f23ee2c5c734ea85f35c8b1fb8 100644 (file)
@@ -41,11 +41,11 @@ namespace KIO
 }
 
 /**
- * @brief Button of the Url navigator which contains one part of an Url.
+ * @brief Button of the URL navigator which contains one part of an URL.
  *
- * It is possible to drop a various number of items to an Url button. In this case
+ * It is possible to drop a various number of items to an UrlNavigatorButton. In this case
  * a context menu is opened where the user must select whether he wants
- * to copy, move or link the dropped items to the Url part indicated by
+ * to copy, move or link the dropped items to the URL part indicated by
  * the button.
  */
 class UrlNavigatorButton : public UrlButton
@@ -56,10 +56,13 @@ public:
     UrlNavigatorButton(int index, UrlNavigator* parent = 0);
     virtual ~UrlNavigatorButton();
     void setIndex(int index);
-    int index() const;
+    int index() const { return m_index; }
+
+    /** @see QWidget::sizeHint() */
+    virtual QSize sizeHint() const;
 
 protected:
-    virtual void drawButton(QPainter* painter);
+    virtual void paintEvent(QPaintEvent* event);
     virtual void enterEvent(QEvent* event);
     virtual void leaveEvent(QEvent* event);
     virtual void dropEvent(QDropEvent* event);