2009-04-15 01:59:54 +00:00
|
|
|
/*
|
2014-01-18 20:56:57 +00:00
|
|
|
* This file Copyright (C) 2010-2014 Mnemosyne LLC
|
2009-04-15 01:59:54 +00:00
|
|
|
*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2009-04-15 01:59:54 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-15 01:59:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QStyleOption>
|
|
|
|
#include <QStyleOptionButton>
|
|
|
|
#include <QStylePainter>
|
|
|
|
|
|
|
|
#include "hig.h"
|
|
|
|
#include "triconpushbutton.h"
|
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
TrIconPushButton :: TrIconPushButton (QWidget * parent):
|
|
|
|
QPushButton (parent)
|
2009-04-15 01:59:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
TrIconPushButton :: TrIconPushButton (const QIcon& icon, QWidget * parent):
|
|
|
|
QPushButton (parent)
|
2009-04-15 01:59:54 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
setIcon (icon);
|
2009-04-15 01:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize
|
|
|
|
TrIconPushButton :: sizeHint () const
|
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QSize s = iconSize ();
|
|
|
|
s.rwidth() += HIG::PAD_SMALL*2;
|
|
|
|
return s;
|
2009-04-15 01:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
TrIconPushButton :: paintEvent (QPaintEvent *)
|
2009-04-15 01:59:54 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QStylePainter p (this);
|
|
|
|
QStyleOptionButton opt;
|
|
|
|
initStyleOption (&opt);
|
2009-04-15 01:59:54 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
QIcon::Mode mode = opt.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled;
|
|
|
|
if ((mode == QIcon::Normal) && (opt.state & QStyle::State_HasFocus))
|
|
|
|
mode = QIcon::Active;
|
|
|
|
QPixmap pixmap = opt.icon.pixmap (opt.iconSize, QIcon::Active, QIcon::On);
|
|
|
|
QRect iconRect (opt.rect.x() + HIG::PAD_SMALL,
|
|
|
|
opt.rect.y() + (opt.rect.height() - pixmap.height())/2,
|
|
|
|
pixmap.width(),
|
|
|
|
pixmap.height());
|
|
|
|
if (opt.state & (QStyle::State_On | QStyle::State_Sunken))
|
|
|
|
iconRect.translate (style()->pixelMetric (QStyle::PM_ButtonShiftHorizontal, &opt, this),
|
|
|
|
style()->pixelMetric (QStyle::PM_ButtonShiftVertical, &opt, this));
|
2009-04-15 01:59:54 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
p.drawPixmap(iconRect, pixmap);
|
2009-04-15 01:59:54 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
if (opt.state & QStyle::State_HasFocus)
|
|
|
|
p.drawPrimitive (QStyle::PE_FrameFocusRect, opt);
|
2009-04-15 01:59:54 +00:00
|
|
|
}
|