1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-02 16:31:23 +00:00

Get rid of using deprecated Q3Button::drawButton() interface. Now the URL navigator looks nearly as nice as within the Qt3version again :-)

svn path=/trunk/playground/utils/dolphin/; revision=607457
This commit is contained in:
Peter Penz 2006-11-24 18:34:52 +00:00
parent 47fa21aff1
commit 4ff8dbf5e9
4 changed files with 46 additions and 32 deletions

View 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)

View 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:
/**

View 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,

View 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);