1
/*****************************************************************************
2
* This file is part of Kiten, a KDE Japanese Reference Tool *
3
* Copyright (C) 2006 Joseph Kerian <jkerian@gmail.com> *
5
* This library is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU Library General Public *
7
* License as published by the Free Software Foundation; either *
8
* version 2 of the License, or (at your option) any later version. *
10
* This library is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13
* Library General Public License for more details. *
15
* You should have received a copy of the GNU Library General Public License *
16
* along with this library; see the file COPYING.LIB. If not, write to *
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18
* Boston, MA 02110-1301, USA. *
19
*****************************************************************************/
21
#include "radicalbutton.h"
23
#include <KApplication>
26
#include <QMouseEvent>
27
#include <QPushButton>
30
#include <QStyleOptionButton>
33
RadicalButton::RadicalButton( const QString &text, QWidget *parent )
34
: QPushButton( text, parent )
39
RadicalButton::~RadicalButton()
43
bool RadicalButton::event( QEvent *event )
45
//This button does not handle wheel events, and unlike
46
//the superclass, we don't care if we're enabled or disabled
47
//(the superclass eats wheel events when disabled)
48
if( event->type() == QEvent::Wheel )
52
return QPushButton::event( event );
55
QSize RadicalButton::minimumSizeHint() const
57
int width = fontMetrics().size( Qt::TextShowMnemonic, text() ).width();
58
int height = QPushButton::sizeHint().height();
59
//TODO: RadicalButton size calculation right, one of these days
60
// QSize sz = fontMetrics().size(Qt::TextShowMnemonic, *it);
61
// setMinimumSize(sz);
63
// QStyleOptionButton opt;
64
// opt.initFrom(this);
65
// QRect rect = kapp->style()->subElementRect(QStyle::SE_PushButtonContents,&opt,this);
66
return QSize( width, height );
69
void RadicalButton::mousePressEvent( QMouseEvent *e )
71
QPushButton::mousePressEvent( e );
72
if( e->button() == Qt::RightButton )
74
setStatus( kRelated );
75
emit userClicked( text(), kRelated );
79
void RadicalButton::mouseReleaseEvent( QMouseEvent *e )
81
QPushButton::mouseReleaseEvent( e );
82
if( e->button() == Qt::LeftButton )
88
emit userClicked( text(), kNormal );
91
setStatus( kSelected );
92
emit userClicked( text(), kSelected );
97
void RadicalButton::resetButton()
102
void RadicalButton::setStatus( RadicalButton::ButtonStatus newStatus )
104
if( m_status == newStatus )
109
//Because it's more work to check everything rather than just set it,
110
//we'll just set everything every time
111
bool checked = false,
123
case kNotAppropriate:
133
QFont theFont = font();
134
theFont.setUnderline( underline );
135
theFont.setItalic( italic );
137
setVisible( ! hidden );
138
setEnabled( ! disabled );
139
setChecked( checked );
140
m_status = newStatus;
143
QSize RadicalButton::sizeHint() const
145
return minimumSizeHint();
148
#include "radicalbutton.moc"