source: trunk/qt/triconpushbutton.cc @ 14377

Last change on this file since 14377 was 14377, checked in by mikedld, 8 years ago

Strip spaces around :: in C++ code (Qt client)

  • Property svn:keywords set to Date Rev Author Id
File size: 1.6 KB
Line 
1/*
2 * This file Copyright (C) 2009-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU Public License v2 or v3 licenses,
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: triconpushbutton.cc 14377 2014-12-12 23:05:10Z mikedld $
8 */
9
10#include <iostream>
11#include <QIcon>
12#include <QStyleOption>
13#include <QStyleOptionButton>
14#include <QStylePainter>
15
16#include "hig.h"
17#include "triconpushbutton.h"
18
19TrIconPushButton::TrIconPushButton (QWidget * parent):
20  QPushButton (parent)
21{
22}
23
24TrIconPushButton::TrIconPushButton (const QIcon& icon, QWidget * parent):
25  QPushButton (parent)
26{
27  setIcon (icon);
28}
29
30QSize
31TrIconPushButton::sizeHint () const
32{
33  QSize s = iconSize ();
34  s.rwidth() += HIG::PAD_SMALL*2;
35  return s;
36}
37
38void
39TrIconPushButton::paintEvent (QPaintEvent *)
40{
41  QStylePainter p (this);
42  QStyleOptionButton opt;
43  initStyleOption (&opt);
44
45  QIcon::Mode mode = opt.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled;
46  if ((mode == QIcon::Normal) &&  (opt.state & QStyle::State_HasFocus))
47    mode = QIcon::Active;
48  QPixmap pixmap = opt.icon.pixmap (opt.iconSize, QIcon::Active, QIcon::On);
49  QRect iconRect (opt.rect.x() + HIG::PAD_SMALL,
50                  opt.rect.y() + (opt.rect.height() - pixmap.height())/2,
51                  pixmap.width(),
52                  pixmap.height());
53  if (opt.state &  (QStyle::State_On | QStyle::State_Sunken))
54    iconRect.translate (style()->pixelMetric (QStyle::PM_ButtonShiftHorizontal, &opt, this),
55                        style()->pixelMetric (QStyle::PM_ButtonShiftVertical, &opt, this));
56
57  p.drawPixmap(iconRect, pixmap);
58
59  if (opt.state & QStyle::State_HasFocus)
60    p.drawPrimitive (QStyle::PE_FrameFocusRect, opt);
61}
Note: See TracBrowser for help on using the repository browser.