diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2010-04-08 02:53:38 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2010-04-08 02:53:38 +0200 |
commit | 43dc2695d62fd2e4fc01aff608bb2af3e8335040 (patch) | |
tree | e854bca16452965d5e4d38bc1d36459bf723355f /src/urlbar/lineedit.cpp | |
parent | rekonq 0.4.59 (diff) | |
download | rekonq-43dc2695d62fd2e4fc01aff608bb2af3e8335040.tar.xz |
This is a really big commit, implementing the new urlbar
- removed previous SSL animation, we have now a nice yellow lock :)
- faster and cleaner animations
- reenabled the old stacked widget, to avoid stupid refreshes and fix some regressions
- implemented some "right icons": KGet, SSL, RSS. For now, just SSL is full featured
- clean up the box :) Some old & unuseful files removed, some icons added
- Pano's request: grey text shown everytime in the empty bar
Again and again:
this is not the first, but the second implementation of the new urlbar UI.
About me this is clearly better than the first or the previous.
But it needs love :D
BUG: 230125
BUG: 231015
CCBUG: 228040
BUG: 227272
Diffstat (limited to 'src/urlbar/lineedit.cpp')
-rw-r--r-- | src/urlbar/lineedit.cpp | 97 |
1 files changed, 75 insertions, 22 deletions
diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp index f7af1f61..8e689a46 100644 --- a/src/urlbar/lineedit.cpp +++ b/src/urlbar/lineedit.cpp @@ -33,6 +33,8 @@ // KDE Includes #include <klocalizedstring.h> #include <KDebug> +#include <KStandardDirs> +#include <KIconLoader> // Qt Includes #include <QtGui/QContextMenuEvent> @@ -42,6 +44,18 @@ #include <QPainter> +IconButton::IconButton(QWidget *parent) + : QToolButton(parent) +{ + setToolButtonStyle(Qt::ToolButtonIconOnly); + setStyleSheet("IconButton { background-color:transparent; border: none; padding: 0px}"); + setCursor(Qt::ArrowCursor); +} + + +// ----------------------------------------------------------------------------------------------------------- + + LineEdit::LineEdit(QWidget* parent) : KLineEdit(parent) , _icon( new IconButton(this) ) @@ -49,8 +63,11 @@ LineEdit::LineEdit(QWidget* parent) // cosmetic setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setMinimumWidth(200); - setMinimumHeight(26); - updateStyles(); + setMinimumHeight(20); + + // initial style + _icon->move(4,6); + setStyleSheet( QString("LineEdit { padding: 0 0 0 %1px;} ").arg(_icon->sizeHint().width()) ); // doesn't show the clear button setClearButtonShown(false); @@ -75,22 +92,6 @@ LineEdit::~LineEdit() } -void LineEdit::updateStyles() -{ - adjustSize(); - _icon->adjustSize(); - if(_icon->toolButtonStyle() == Qt::ToolButtonIconOnly) - _icon->move( 4, 3); - else - _icon->move( 2, 1); - - int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - setStyleSheet(QString("LineEdit { padding-left: %1px; } ").arg(_icon->sizeHint().width() + frameWidth + 1)); - - update(); -} - - void LineEdit::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Escape) @@ -117,18 +118,70 @@ IconButton *LineEdit::iconButton() const void LineEdit::paintEvent(QPaintEvent *event) { + // you need this before our code to draw inside the line edit.. KLineEdit::paintEvent(event); - if (text().isEmpty() && !hasFocus()) - { + if (text().isEmpty()) + { QStyleOptionFrame option; initStyleOption(&option); QRect textRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this); QPainter painter(this); painter.setPen(Qt::gray); painter.drawText( textRect, - Qt::AlignLeft | Qt::AlignVCenter, - i18n("Search Bookmarks, History, Google.. and the Kitchen Sink!") + Qt::AlignCenter, + i18n("Search Bookmarks, History, Google.. just start typing here!") ); } } + + +IconButton *LineEdit::addRightIcon(LineEdit::icon ic) +{ + IconButton *rightIcon = new IconButton(this); + + switch(ic) + { + case LineEdit::KGet: + rightIcon->setIcon( QIcon(KStandardDirs::locate("data", "rekonq/pics/kget-icon.png")) ); + break; + case LineEdit::RSS: + rightIcon->setIcon( QIcon(KStandardDirs::locate("data", "rekonq/pics/rss-icon.png")) ); + break; + case LineEdit::SSL: + rightIcon->setIcon( QIcon(KStandardDirs::locate("data", "rekonq/pics/ssl-icon.png")) ); + break; + default: + kDebug() << "ERROR.. default non extant case!!"; + break; + } + + _rightIconsList << rightIcon; + int iconsCount = _rightIconsList.count(); + rightIcon->move( width() - 23*iconsCount, 6); + rightIcon->show(); + + return rightIcon; +} + + +void LineEdit::clearRightIcons() +{ + qDeleteAll(_rightIconsList); + _rightIconsList.clear(); +} + + +void LineEdit::resizeEvent(QResizeEvent *event) +{ + KLineEdit::resizeEvent(event); + + int iconsCount = _rightIconsList.count(); + int w = width(); + + for(int i = 0; i < iconsCount; ++i) + { + IconButton *bt = _rightIconsList.at(i); + bt->move( w - 23*(i+1), 6); + } +} |