kexi

kexismalltoolbutton.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexismalltoolbutton.h"
21
22#include <tqtooltip.h>
23#include <tqwhatsthis.h>
24#include <tqstyle.h>
25
26#include <kiconloader.h>
27#include <tdeglobalsettings.h>
28
29#include <core/kexi.h>
30
31KexiSmallToolButton::KexiSmallToolButton(TQWidget* parent, const TQString& text,
32 const TQString& icon, const char* name)
33 : TQToolButton(parent, name)
34{
35 init();
36 update(text, SmallIconSet(icon));
37}
38
39KexiSmallToolButton::KexiSmallToolButton(TQWidget* parent, const TQString& text,
40 const TQIconSet& iconSet, const char* name)
41 : TQToolButton(parent, name)
42{
43 init();
44 update(text, iconSet);
45}
46
47KexiSmallToolButton::KexiSmallToolButton(TQWidget* parent, TDEAction* action)
48 : TQToolButton(parent, action->name())
49 , m_action(action)
50{
51 init();
52 connect(this, TQ_SIGNAL(clicked()), action, TQ_SLOT(activate()));
53 connect(action, TQ_SIGNAL(enabled(bool)), this, TQ_SLOT(setEnabled(bool)));
54 updateAction();
55}
56
57KexiSmallToolButton::~KexiSmallToolButton()
58{
59}
60
61void KexiSmallToolButton::updateAction()
62{
63 if (!m_action)
64 return;
65 update(m_action->text(), m_action->iconSet(TDEIcon::Small));
66 setAccel(m_action->shortcut());
67 TQToolTip::add(this, m_action->toolTip());
68 TQWhatsThis::add(this, m_action->whatsThis());
69}
70
71void KexiSmallToolButton::init()
72{
73 setPaletteBackgroundColor(palette().active().background());
74 setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Preferred);
75 TQFont f(TDEGlobalSettings::toolBarFont());
76 f.setPixelSize(Kexi::smallFont().pixelSize());
77 setFont(f);
78 setAutoRaise(true);
79}
80
81void KexiSmallToolButton::update(const TQString& text, const TQIconSet& iconSet, bool tipToo)
82{
83 int width = 0;
84 if (text.isEmpty()) {
85 width = 10;
86 setUsesTextLabel(false);
87 }
88 else {
89 width += TQFontMetrics(font()).width(text+" ");
90 setUsesTextLabel(true);
91 setTextPosition(TQToolButton::Right);
92 TQToolButton::setTextLabel(text, tipToo);
93 }
94 if (!iconSet.isNull()) {
95 width += IconSize(TDEIcon::Small);
96 TQToolButton::setIconSet(iconSet);
97 }
98 setFixedWidth( width );
99}
100
101void KexiSmallToolButton::setIconSet( const TQIconSet& iconSet )
102{
103 update(textLabel(), iconSet);
104}
105
106void KexiSmallToolButton::setIconSet( const TQString& icon )
107{
108 setIconSet( SmallIconSet(icon) );
109}
110
111void KexiSmallToolButton::setTextLabel( const TQString & newLabel, bool tipToo )
112{
113 Q_UNUSED( tipToo );
114
115 update(newLabel, iconSet());
116}
117
118void KexiSmallToolButton::drawButton( TQPainter *_painter )
119{
120 TQToolButton::drawButton(_painter);
121 if (TQToolButton::popup()) {
122 TQStyle::SFlags arrowFlags = TQStyle::Style_Default;
123 if (isDown())
124 arrowFlags |= TQStyle::Style_Down;
125 if (isEnabled())
126 arrowFlags |= TQStyle::Style_Enabled;
127 style().drawPrimitive(TQStyle::PE_ArrowDown, _painter,
128 TQRect(width()-7, height()-7, 5, 5), colorGroup(),
129 arrowFlags, TQStyleOption() );
130 }
131}
132
133#include "kexismalltoolbutton.moc"
KEXICORE_EXPORT TQFont smallFont(TQWidget *init=0)
Definition kexi.cpp:143