• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kkeybutton.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
3  Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
4 
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.
9 
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.
14 
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 */
20 
21 #include "kkeybutton.h"
22 #include "tdeshortcutdialog.h"
23 
24 #include <tqcursor.h>
25 #include <tqdrawutil.h>
26 #include <tqpainter.h>
27 #include <tdeapplication.h>
28 #include <kdebug.h>
29 #include <kglobalaccel.h>
30 #include <tdelocale.h>
31 
32 #include "config.h"
33 #ifdef Q_WS_X11
34 #define XK_XKB_KEYS
35 #define XK_MISCELLANY
36 #include <X11/Xlib.h> // For x11Event()
37 #include <X11/keysymdef.h> // For XK_...
38 
39 #ifdef KeyPress
40 const int XFocusOut = FocusOut;
41 const int XFocusIn = FocusIn;
42 const int XKeyPress = KeyPress;
43 const int XKeyRelease = KeyRelease;
44 #undef KeyRelease
45 #undef KeyPress
46 #undef FocusOut
47 #undef FocusIn
48 #endif // KeyPress
49 #endif // Q_WS_X11
50 
51 //static const char* psTemp[] = {
52 // I18N_NOOP("Primary"), I18N_NOOP("Alternate"), I18N_NOOP("Multi-Key")
53 //};
54 
55 class KKeyButtonPrivate
56 {
57  public:
58  bool bQtShortcut;
59 };
60 
61 /***********************************************************************/
62 /* KKeyButton */
63 /* */
64 /* Initially added by Mark Donohoe <donohoe@kde.org> */
65 /* */
66 /***********************************************************************/
67 
68 KKeyButton::KKeyButton(TQWidget *parent, const char *name)
69 : TQPushButton( parent, name )
70 {
71  d = new KKeyButtonPrivate;
72  setFocusPolicy( TQ_StrongFocus );
73  m_bEditing = false;
74  connect( this, TQT_SIGNAL(clicked()), this, TQT_SLOT(captureShortcut()) );
75  setShortcut( TDEShortcut(), true );
76 }
77 
78 KKeyButton::~KKeyButton ()
79 {
80  delete d;
81 }
82 
83 void KKeyButton::setShortcut( const TDEShortcut& cut, bool bQtShortcut )
84 {
85  d->bQtShortcut = bQtShortcut;
86  m_cut = cut;
87  TQString keyStr = m_cut.toString();
88  keyStr.replace('&', TQString::fromLatin1("&&"));
89  setText( keyStr.isEmpty() ? i18n("None") : keyStr );
90 }
91 
92 // deprecated //
93 void KKeyButton::setShortcut( const TDEShortcut& cut )
94 {
95  setShortcut( cut, false );
96 }
97 
98 void KKeyButton::setText( const TQString& text )
99 {
100  TQPushButton::setText( text );
101  setFixedSize( sizeHint().width()+12, sizeHint().height()+8 );
102 }
103 
104 void KKeyButton::captureShortcut()
105 {
106  TDEShortcut cut;
107 
108  m_bEditing = true;
109  repaint();
110 
111  {
112  TDEShortcutDialog dlg( m_cut, d->bQtShortcut, this );
113  if( dlg.exec() == KDialog::Accepted )
114  cut = dlg.shortcut();
115  } // emit the signal after the dialog is destroyed, otherwise it still has grab
116  if( !cut.isNull())
117  emit capturedShortcut( cut );
118 
119  m_bEditing = false;
120  repaint();
121 }
122 
123 void KKeyButton::drawButton( TQPainter *painter )
124 {
125  TQPointArray a( 4 );
126  a.setPoint( 0, 0, 0) ;
127  a.setPoint( 1, width(), 0 );
128  a.setPoint( 2, 0, height() );
129  a.setPoint( 3, 0, 0 );
130 
131  TQRegion r1( a );
132  painter->setClipRegion( r1 );
133  painter->setBrush( backgroundColor().light() );
134  painter->drawRoundRect( 0, 0, width(), height(), 20, 20);
135 
136  a.setPoint( 0, width(), height() );
137  a.setPoint( 1, width(), 0 );
138  a.setPoint( 2, 0, height() );
139  a.setPoint( 3, width(), height() );
140 
141  TQRegion r2( a );
142  painter->setClipRegion( r2 );
143  painter->setBrush( backgroundColor().dark() );
144  painter->drawRoundRect( 0, 0, width(), height(), 20, 20 );
145 
146  painter->setClipping( false );
147  if( width() > 12 && height() > 8 )
148  qDrawShadePanel( painter, 6, 4, width() - 12, height() - 8,
149  colorGroup(), true, 1, 0L );
150  if ( m_bEditing )
151  {
152  painter->setPen( colorGroup().base() );
153  painter->setBrush( colorGroup().base() );
154  }
155  else
156  {
157  painter->setPen( backgroundColor() );
158  painter->setBrush( backgroundColor() );
159  }
160  if( width() > 14 && height() > 10 )
161  painter->drawRect( 7, 5, width() - 14, height() - 10 );
162 
163  drawButtonLabel( painter );
164 
165  painter->setPen( colorGroup().text() );
166  painter->setBrush( NoBrush );
167  if( hasFocus() || m_bEditing )
168  {
169  if( width() > 16 && height() > 12 )
170  painter->drawRect( 8, 6, width() - 16, height() - 12 );
171  }
172 
173 }
174 
175 void KKeyButton::virtual_hook( int, void* )
176 { /*BASE::virtual_hook( id, data );*/ }
177 
178 #include "kkeybutton.moc"
KKeyButton::captureShortcut
void captureShortcut()
Call this method to capture a shortcut from the keyboard.
Definition: kkeybutton.cpp:104
KKeyButton::setText
void setText(const TQString &text)
Reimplemented for internal purposes.
Definition: kkeybutton.cpp:98
KKeyButton::KKeyButton
KKeyButton(TQWidget *parent=0, const char *name=0)
Constructs key button widget.
Definition: kkeybutton.cpp:68
TDEShortcutDialog
Dialog for configuring a shortcut.
Definition: tdeshortcutdialog.h:41
TDEShortcut::isNull
bool isNull() const
KKeyButton::setShortcut
void setShortcut(const TDEShortcut &cut) KDE_DEPRECATED
Definition: kkeybutton.cpp:93
tdelocale.h
KKeyButton::~KKeyButton
virtual ~KKeyButton()
Destructs the key button widget.
Definition: kkeybutton.cpp:78
KKeyButton::drawButton
void drawButton(TQPainter *_painter)
Reimplemented for internal reasons.
Definition: kkeybutton.cpp:123
TDEShortcut::toString
TQString toString() const
TDEShortcut

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.