diff options
author | Alessio Treglia <alessio@debian.org> | 2012-02-16 11:08:45 +0100 |
---|---|---|
committer | Alessio Treglia <alessio@debian.org> | 2012-02-16 11:08:45 +0100 |
commit | 65a64d260e05c7bf8d3bdf82e796637dc820e574 (patch) | |
tree | 600c2becea7f28fdefff51200bb3ed33514e4cc7 /src/lineedit_with_icon.cpp | |
parent | 1d323e54ee434609cf035598486075c9a918a2d3 (diff) |
Imported Upstream version 0.7.0
Diffstat (limited to 'src/lineedit_with_icon.cpp')
-rw-r--r-- | src/lineedit_with_icon.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/lineedit_with_icon.cpp b/src/lineedit_with_icon.cpp new file mode 100644 index 0000000..906c6e1 --- /dev/null +++ b/src/lineedit_with_icon.cpp @@ -0,0 +1,70 @@ +/* smplayer, GUI front-end for mplayer. + Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "lineedit_with_icon.h" +#include <QToolButton> +#include <QStyle> +#include <QEvent> + +LineEditWithIcon::LineEditWithIcon(QWidget *parent) : QLineEdit(parent) +{ + button = new QToolButton(this); + button->setCursor(Qt::ArrowCursor); + setupButton(); +} + +void LineEditWithIcon::setupButton() { +} + +void LineEditWithIcon::setIcon(const QPixmap & pixmap) { + QPixmap p = pixmap; + //qDebug("height: %d, icon height: %d", height(), p.height()); + int max_height = 16; + if (max_height > height()) max_height = height() - 4; + if (pixmap.height() > max_height) p = pixmap.scaledToHeight(max_height, Qt::SmoothTransformation); + button->setIcon(p); + button->setStyleSheet("QToolButton { border: none; padding: 0px; }"); + + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + //qDebug("frameWidth: %d", frameWidth); + setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(button->sizeHint().width() + frameWidth + 1)); + /* + QSize msz = minimumSizeHint(); + setMinimumSize(qMax(msz.width(), button->sizeHint().height() + frameWidth * 2 + 2), + qMax(msz.height(), button->sizeHint().height() + frameWidth * 2 + 2)); + */ +} + +void LineEditWithIcon::resizeEvent(QResizeEvent *) +{ + QSize sz = button->sizeHint(); + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + button->move(rect().right() - frameWidth - sz.width(), + (rect().bottom() + 1 - sz.height())/2); +} + +// Language change stuff +void LineEditWithIcon::changeEvent(QEvent *e) { + if (e->type() == QEvent::LanguageChange) { + setupButton(); + } else { + QWidget::changeEvent(e); + } +} + +#include "moc_lineedit_with_icon.cpp" |