source: smplayer/trunk/src/lineedit_with_icon.cpp

Last change on this file was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

File size: 2.5 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
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() && height() >= 8) 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 QSize sz = button->sizeHint();
55 int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
56 button->move(rect().right() - frameWidth - sz.width(),
57 (rect().bottom() + 1 - sz.height())/2);
58}
59
60// Language change stuff
61void LineEditWithIcon::changeEvent(QEvent *e) {
62 if (e->type() == QEvent::LanguageChange) {
63 setupButton();
64 } else {
65 QLineEdit::changeEvent(e);
66 }
67}
68
69#include "moc_lineedit_with_icon.cpp"
Note: See TracBrowser for help on using the repository browser.