2009-04-15 01:59:54 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2009-2014 Mnemosyne LLC
|
2009-04-15 01:59:54 +00:00
|
|
|
*
|
2014-01-19 01:09:44 +00:00
|
|
|
* It may be used under the GNU Public License v2 or v3 licenses,
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
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
|
|
|
}
|