source: smplayer/vendor/current/src/lineedit_with_icon.cpp@ 163

Last change on this file since 163 was 163, checked in by Silvan Scherrer, 12 years ago

SMPlayer: update vendor to 0.8.7

File size: 2.4 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2014 Ricardo Villalba <[email protected]>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "lineedit_with_icon.h"
20#include <QToolButton>
21#include <QStyle>
22#include <QEvent>
23
24LineEditWithIcon::LineEditWithIcon(QWidget *parent) : QLineEdit(parent)
25{
26 button = new QToolButton(this);
27 button->setCursor(Qt::ArrowCursor);
28 setupButton();
29}
30
31void LineEditWithIcon::setupButton() {
32}
33
34void LineEditWithIcon::setIcon(const QPixmap & pixmap) {
35 QPixmap p = pixmap;
36 //qDebug("height: %d, icon height: %d", height(), p.height());
37 int max_height = 16;
38 if (max_height > height()) max_height = height() - 4;
39 if (pixmap.height() > max_height) p = pixmap.scaledToHeight(max_height, Qt::SmoothTransformation);
40 button->setIcon(p);
41 button->setStyleSheet("QToolButton { border: none; padding: 0px; }");
42
43 int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
44 //qDebug("frameWidth: %d", frameWidth);
45 setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(button->sizeHint().width() + frameWidth + 1));
46 /*
47 QSize msz = minimumSizeHint();
48 setMinimumSize(qMax(msz.width(), button->sizeHint().height() + frameWidth * 2 + 2),
49 qMax(msz.height(), button->sizeHint().height() + frameWidth * 2 + 2));
50 */
51}
52
53void LineEditWithIcon::resizeEvent(QResizeEvent *)
54{
55 QSize sz = button->sizeHint();
56 int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
57 button->move(rect().right() - frameWidth - sz.width(),
58 (rect().bottom() + 1 - sz.height())/2);
59}
60
61// Language change stuff
62void LineEditWithIcon::changeEvent(QEvent *e) {
63 if (e->type() == QEvent::LanguageChange) {
64 setupButton();
65 } else {
66 QWidget::changeEvent(e);
67 }
68}
69
70#include "moc_lineedit_with_icon.cpp"
Note: See TracBrowser for help on using the repository browser.