2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "fancylineedit.h"
|
2012-08-23 14:10:12 +02:00
|
|
|
#include "historycompleter.h"
|
|
|
|
|
#include "qtcassert.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QEvent>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QAbstractButton>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QStyle>
|
|
|
|
|
#include <QPaintEvent>
|
2012-07-05 11:21:46 +02:00
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
|
|
|
|
|
/*! Opens a menu at the specified widget position.
|
|
|
|
|
* This functions computes the position where to show the menu, and opens it with
|
|
|
|
|
* QMenu::exec().
|
|
|
|
|
* \param menu The menu to open
|
|
|
|
|
* \param widget The widget next to which to open the menu
|
|
|
|
|
*/
|
|
|
|
|
static void execMenuAtWidget(QMenu *menu, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
QPoint p;
|
|
|
|
|
QRect screen = qApp->desktop()->availableGeometry(widget);
|
|
|
|
|
QSize sh = menu->sizeHint();
|
|
|
|
|
QRect rect = widget->rect();
|
|
|
|
|
if (widget->isRightToLeft()) {
|
|
|
|
|
if (widget->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) {
|
|
|
|
|
p = widget->mapToGlobal(rect.bottomRight());
|
|
|
|
|
} else {
|
|
|
|
|
p = widget->mapToGlobal(rect.topRight() - QPoint(0, sh.height()));
|
|
|
|
|
}
|
|
|
|
|
p.rx() -= sh.width();
|
|
|
|
|
} else {
|
|
|
|
|
if (widget->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) {
|
|
|
|
|
p = widget->mapToGlobal(rect.bottomLeft());
|
|
|
|
|
} else {
|
|
|
|
|
p = widget->mapToGlobal(rect.topLeft() - QPoint(0, sh.height()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width()));
|
|
|
|
|
p.ry() += 1;
|
|
|
|
|
|
|
|
|
|
menu->exec(p);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-03-02 17:13:33 +01:00
|
|
|
/*!
|
|
|
|
|
\class Utils::FancyLineEdit
|
|
|
|
|
|
|
|
|
|
\brief A line edit with an embedded pixmap on one side that is connected to
|
|
|
|
|
a menu.
|
|
|
|
|
|
|
|
|
|
Additionally, it can display a grayed hintText (like "Type Here to")
|
|
|
|
|
when not focused and empty. When connecting to the changed signals and
|
|
|
|
|
querying text, one has to be aware that the text is set to that hint
|
|
|
|
|
text if isShowingHintText() returns true (that is, does not contain
|
|
|
|
|
valid user input).
|
|
|
|
|
*/
|
|
|
|
|
|
2010-04-12 19:45:36 +02:00
|
|
|
enum { margin = 6 };
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
#define ICONBUTTON_HEIGHT 18
|
2010-04-12 19:45:36 +02:00
|
|
|
#define FADE_TIME 160
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-04-12 19:45:36 +02:00
|
|
|
namespace Utils {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-04-12 19:45:36 +02:00
|
|
|
// --------- FancyLineEditPrivate
|
2012-08-23 14:10:12 +02:00
|
|
|
class FancyLineEditPrivate : public QObject
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
2009-11-27 13:54:27 +01:00
|
|
|
explicit FancyLineEditPrivate(FancyLineEdit *parent);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
virtual bool eventFilter(QObject *obj, QEvent *event);
|
|
|
|
|
|
2009-11-27 13:54:27 +01:00
|
|
|
FancyLineEdit *m_lineEdit;
|
2010-07-01 09:32:47 +02:00
|
|
|
QPixmap m_pixmap[2];
|
|
|
|
|
QMenu *m_menu[2];
|
|
|
|
|
bool m_menuTabFocusTrigger[2];
|
|
|
|
|
IconButton *m_iconbutton[2];
|
|
|
|
|
bool m_iconEnabled[2];
|
2012-08-23 14:10:12 +02:00
|
|
|
|
2012-08-24 13:05:09 +02:00
|
|
|
HistoryCompleter *m_historyCompleter;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2009-11-27 13:54:27 +01:00
|
|
|
FancyLineEditPrivate::FancyLineEditPrivate(FancyLineEdit *parent) :
|
2012-08-24 13:05:09 +02:00
|
|
|
QObject(parent), m_lineEdit(parent), m_historyCompleter(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-01 09:32:47 +02:00
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
m_menu[i] = 0;
|
|
|
|
|
m_menuTabFocusTrigger[i] = false;
|
|
|
|
|
m_iconbutton[i] = new IconButton(parent);
|
|
|
|
|
m_iconbutton[i]->installEventFilter(this);
|
|
|
|
|
m_iconbutton[i]->hide();
|
|
|
|
|
m_iconbutton[i]->setAutoHide(false);
|
|
|
|
|
m_iconEnabled[i] = false;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FancyLineEditPrivate::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
|
{
|
2010-07-01 09:32:47 +02:00
|
|
|
int buttonIndex = -1;
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
if (obj == m_iconbutton[i]) {
|
|
|
|
|
buttonIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (buttonIndex == -1)
|
2008-12-02 12:01:29 +01:00
|
|
|
return QObject::eventFilter(obj, event);
|
|
|
|
|
switch (event->type()) {
|
|
|
|
|
case QEvent::FocusIn:
|
2010-07-01 09:32:47 +02:00
|
|
|
if (m_menuTabFocusTrigger[buttonIndex] && m_menu[buttonIndex]) {
|
2008-12-02 12:01:29 +01:00
|
|
|
m_lineEdit->setFocus();
|
2012-07-05 11:21:46 +02:00
|
|
|
execMenuAtWidget(m_menu[buttonIndex], m_iconbutton[buttonIndex]);
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return QObject::eventFilter(obj, event);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-12 19:45:36 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// --------- FancyLineEdit
|
|
|
|
|
FancyLineEdit::FancyLineEdit(QWidget *parent) :
|
|
|
|
|
QLineEdit(parent),
|
2011-09-15 13:42:38 +02:00
|
|
|
d(new FancyLineEditPrivate(this))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-04-12 19:45:36 +02:00
|
|
|
ensurePolished();
|
2010-07-01 09:32:47 +02:00
|
|
|
updateMargins();
|
2010-04-12 19:45:36 +02:00
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
connect(this, SIGNAL(textChanged(QString)), this, SLOT(checkButtons(QString)));
|
2011-09-15 13:42:38 +02:00
|
|
|
connect(d->m_iconbutton[Left], SIGNAL(clicked()), this, SLOT(iconClicked()));
|
|
|
|
|
connect(d->m_iconbutton[Right], SIGNAL(clicked()), this, SLOT(iconClicked()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::checkButtons(const QString &text)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-01 09:32:47 +02:00
|
|
|
if (m_oldText.isEmpty() || text.isEmpty()) {
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
2011-09-15 13:42:38 +02:00
|
|
|
if (d->m_iconbutton[i]->hasAutoHide())
|
|
|
|
|
d->m_iconbutton[i]->animateShow(!text.isEmpty());
|
2010-07-01 09:32:47 +02:00
|
|
|
}
|
2010-04-29 16:48:30 +02:00
|
|
|
m_oldText = text;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-12 19:45:36 +02:00
|
|
|
FancyLineEdit::~FancyLineEdit()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::setButtonVisible(Side side, bool visible)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_iconbutton[side]->setVisible(visible);
|
|
|
|
|
d->m_iconEnabled[side] = visible;
|
2010-07-01 09:32:47 +02:00
|
|
|
updateMargins();
|
|
|
|
|
}
|
2010-04-12 19:45:36 +02:00
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
bool FancyLineEdit::isButtonVisible(Side side) const
|
|
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
return d->m_iconEnabled[side];
|
2010-07-01 09:32:47 +02:00
|
|
|
}
|
2010-04-12 19:45:36 +02:00
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::iconClicked()
|
|
|
|
|
{
|
|
|
|
|
IconButton *button = qobject_cast<IconButton *>(sender());
|
|
|
|
|
int index = -1;
|
|
|
|
|
for (int i = 0; i < 2; ++i)
|
2011-09-15 13:42:38 +02:00
|
|
|
if (d->m_iconbutton[i] == button)
|
2010-07-01 09:32:47 +02:00
|
|
|
index = i;
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return;
|
2011-09-15 13:42:38 +02:00
|
|
|
if (d->m_menu[index]) {
|
2012-07-05 11:21:46 +02:00
|
|
|
execMenuAtWidget(d->m_menu[index], button);
|
2010-07-01 09:32:47 +02:00
|
|
|
} else {
|
|
|
|
|
emit buttonClicked((Side)index);
|
|
|
|
|
if (index == Left)
|
|
|
|
|
emit leftButtonClicked();
|
|
|
|
|
else if (index == Right)
|
|
|
|
|
emit rightButtonClicked();
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-12 19:45:36 +02:00
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::updateMargins()
|
|
|
|
|
{
|
|
|
|
|
bool leftToRight = (layoutDirection() == Qt::LeftToRight);
|
|
|
|
|
Side realLeft = (leftToRight ? Left : Right);
|
|
|
|
|
Side realRight = (leftToRight ? Right : Left);
|
2010-04-12 19:45:36 +02:00
|
|
|
|
2011-09-15 13:42:38 +02:00
|
|
|
int leftMargin = d->m_iconbutton[realLeft]->pixmap().width() + 8;
|
|
|
|
|
int rightMargin = d->m_iconbutton[realRight]->pixmap().width() + 8;
|
2010-04-12 19:45:36 +02:00
|
|
|
// Note KDE does not reserve space for the highlight color
|
|
|
|
|
if (style()->inherits("OxygenStyle")) {
|
2010-07-01 09:32:47 +02:00
|
|
|
leftMargin = qMax(24, leftMargin);
|
|
|
|
|
rightMargin = qMax(24, rightMargin);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-04-12 19:45:36 +02:00
|
|
|
|
2011-09-15 13:42:38 +02:00
|
|
|
QMargins margins((d->m_iconEnabled[realLeft] ? leftMargin : 0), 0,
|
|
|
|
|
(d->m_iconEnabled[realRight] ? rightMargin : 0), 0);
|
2010-04-12 19:45:36 +02:00
|
|
|
|
|
|
|
|
setTextMargins(margins);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::updateButtonPositions()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-01 09:32:47 +02:00
|
|
|
QRect contentRect = rect();
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
Side iconpos = (Side)i;
|
|
|
|
|
if (layoutDirection() == Qt::RightToLeft)
|
|
|
|
|
iconpos = (iconpos == Left ? Right : Left);
|
|
|
|
|
|
|
|
|
|
if (iconpos == FancyLineEdit::Right) {
|
|
|
|
|
const int iconoffset = textMargins().right() + 4;
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_iconbutton[i]->setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0));
|
2010-07-01 09:32:47 +02:00
|
|
|
} else {
|
|
|
|
|
const int iconoffset = textMargins().left() + 4;
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_iconbutton[i]->setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0));
|
2010-07-01 09:32:47 +02:00
|
|
|
}
|
2010-04-12 19:45:36 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyLineEdit::resizeEvent(QResizeEvent *)
|
|
|
|
|
{
|
2010-07-01 09:32:47 +02:00
|
|
|
updateButtonPositions();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::setButtonPixmap(Side side, const QPixmap &buttonPixmap)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_iconbutton[side]->setPixmap(buttonPixmap);
|
2010-07-01 09:32:47 +02:00
|
|
|
updateMargins();
|
|
|
|
|
updateButtonPositions();
|
|
|
|
|
update();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
QPixmap FancyLineEdit::buttonPixmap(Side side) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
return d->m_pixmap[side];
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::setButtonMenu(Side side, QMenu *buttonMenu)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_menu[side] = buttonMenu;
|
|
|
|
|
d->m_iconbutton[side]->setIconOpacity(1.0);
|
2010-04-12 19:45:36 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
QMenu *FancyLineEdit::buttonMenu(Side side) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
return d->m_menu[side];
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
bool FancyLineEdit::hasMenuTabFocusTrigger(Side side) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
return d->m_menuTabFocusTrigger[side];
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::setMenuTabFocusTrigger(Side side, bool v)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
if (d->m_menuTabFocusTrigger[side] == v)
|
2010-04-12 19:45:36 +02:00
|
|
|
return;
|
|
|
|
|
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_menuTabFocusTrigger[side] = v;
|
|
|
|
|
d->m_iconbutton[side]->setFocusPolicy(v ? Qt::TabFocus : Qt::NoFocus);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
bool FancyLineEdit::hasAutoHideButton(Side side) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
return d->m_iconbutton[side]->hasAutoHide();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-24 13:05:09 +02:00
|
|
|
void FancyLineEdit::setHistoryCompleter(const QString &historyKey)
|
2012-08-23 14:10:12 +02:00
|
|
|
{
|
2012-08-24 13:05:09 +02:00
|
|
|
QTC_ASSERT(!d->m_historyCompleter, return);
|
2012-08-27 15:49:08 +03:00
|
|
|
d->m_historyCompleter = new HistoryCompleter(this, historyKey, this);
|
2012-08-24 13:05:09 +02:00
|
|
|
QLineEdit::setCompleter(d->m_historyCompleter);
|
2012-08-23 14:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyLineEdit::setSpecialCompleter(QCompleter *completer)
|
|
|
|
|
{
|
2012-08-24 13:05:09 +02:00
|
|
|
QTC_ASSERT(!d->m_historyCompleter, return);
|
2012-08-23 14:10:12 +02:00
|
|
|
QLineEdit::setCompleter(completer);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::setAutoHideButton(Side side, bool h)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_iconbutton[side]->setAutoHide(h);
|
2010-04-12 19:45:36 +02:00
|
|
|
if (h)
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_iconbutton[side]->setIconOpacity(text().isEmpty() ? 0.0 : 1.0);
|
2010-04-12 19:45:36 +02:00
|
|
|
else
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_iconbutton[side]->setIconOpacity(1.0);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::setButtonToolTip(Side side, const QString &tip)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_iconbutton[side]->setToolTip(tip);
|
2010-04-12 19:45:36 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
void FancyLineEdit::setButtonFocusPolicy(Side side, Qt::FocusPolicy policy)
|
2010-04-12 19:45:36 +02:00
|
|
|
{
|
2011-09-15 13:42:38 +02:00
|
|
|
d->m_iconbutton[side]->setFocusPolicy(policy);
|
2010-04-12 19:45:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IconButton - helper class to represent a clickable icon
|
|
|
|
|
|
|
|
|
|
IconButton::IconButton(QWidget *parent)
|
2010-07-01 09:32:47 +02:00
|
|
|
: QAbstractButton(parent), m_autoHide(false)
|
2010-04-12 19:45:36 +02:00
|
|
|
{
|
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IconButton::paintEvent(QPaintEvent *)
|
|
|
|
|
{
|
|
|
|
|
QPainter painter(this);
|
2010-07-01 09:32:47 +02:00
|
|
|
QRect pixmapRect = QRect(0, 0, m_pixmap.width(), m_pixmap.height());
|
2010-04-27 19:00:51 +02:00
|
|
|
pixmapRect.moveCenter(rect().center());
|
2010-04-12 19:45:36 +02:00
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
if (m_autoHide)
|
2010-04-12 19:45:36 +02:00
|
|
|
painter.setOpacity(m_iconOpacity);
|
|
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
painter.drawPixmap(pixmapRect, m_pixmap);
|
2010-04-12 19:45:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IconButton::animateShow(bool visible)
|
|
|
|
|
{
|
|
|
|
|
if (visible) {
|
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity");
|
|
|
|
|
animation->setDuration(FADE_TIME);
|
|
|
|
|
animation->setEndValue(1.0);
|
|
|
|
|
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
|
} else {
|
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity");
|
|
|
|
|
animation->setDuration(FADE_TIME);
|
|
|
|
|
animation->setEndValue(0.0);
|
|
|
|
|
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Utils
|