KoTabChooser.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3
4 This library 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 library 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 library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20// Description: Tabulator chooser (header)
21
22/******************************************************************/
23
24#include <KoTabChooser.h>
25#include <tqpainter.h>
26#include <tqpopupmenu.h>
27#include <tqcursor.h>
28
29#include <tdelocale.h>
30
31
32class KoTabChooserPrivate {
33public:
34 KoTabChooserPrivate() {
35 }
36 ~KoTabChooserPrivate() {}
37
38 bool m_bReadWrite;
39};
40
41/******************************************************************/
42/* Class: KoTabChooser */
43/******************************************************************/
44
45/*================================================================*/
46KoTabChooser::KoTabChooser( TQWidget *parent, int _flags )
47 : TQFrame( parent, "" )
48{
49 setFrameStyle( MenuBarPanel );
50 flags = _flags;
51 d=new KoTabChooserPrivate();
52
53 d->m_bReadWrite=true;
54
55 currType = 0;
56
57 if ( flags & TAB_DEC_PNT ) currType = TAB_DEC_PNT;
58 if ( flags & TAB_CENTER ) currType = TAB_CENTER;
59 if ( flags & TAB_RIGHT ) currType = TAB_RIGHT;
60 if ( flags & TAB_LEFT ) currType = TAB_LEFT;
61
62 setupMenu();
63}
64
65/*================================================================*/
66void KoTabChooser::mousePressEvent( TQMouseEvent *e )
67{
68 if ( currType == 0 ) return;
69
70 if( !d->m_bReadWrite)
71 return;
72
73 switch ( e->button() ) {
74 case TQt::LeftButton: case TQt::MidButton: {
75 switch ( currType ) {
76 case TAB_LEFT: {
77 if ( flags & TAB_CENTER ) currType = TAB_CENTER;
78 else if ( flags & TAB_RIGHT ) currType = TAB_RIGHT;
79 else if ( flags & TAB_DEC_PNT ) currType = TAB_DEC_PNT;
80 } break;
81 case TAB_RIGHT: {
82 if ( flags & TAB_DEC_PNT ) currType = TAB_DEC_PNT;
83 else if ( flags & TAB_LEFT ) currType = TAB_LEFT;
84 else if ( flags & TAB_CENTER ) currType = TAB_CENTER;
85 } break;
86 case TAB_CENTER: {
87 if ( flags & TAB_RIGHT ) currType = TAB_RIGHT;
88 else if ( flags & TAB_DEC_PNT ) currType = TAB_DEC_PNT;
89 else if ( flags & TAB_LEFT ) currType = TAB_LEFT;
90 } break;
91 case TAB_DEC_PNT: {
92 if ( flags & TAB_LEFT ) currType = TAB_LEFT;
93 else if ( flags & TAB_CENTER ) currType = TAB_CENTER;
94 else if ( flags & TAB_RIGHT ) currType = TAB_RIGHT;
95 } break;
96 }
97 repaint( true );
98 } break;
99 case TQt::RightButton: {
100 TQPoint pnt( TQCursor::pos() );
101
102 rb_menu->setItemChecked( mLeft, false );
103 rb_menu->setItemChecked( mCenter, false );
104 rb_menu->setItemChecked( mRight, false );
105 rb_menu->setItemChecked( mDecPoint, false );
106
107 switch ( currType ) {
108 case TAB_LEFT: rb_menu->setItemChecked( mLeft, true );
109 break;
110 case TAB_CENTER: rb_menu->setItemChecked( mCenter, true );
111 break;
112 case TAB_RIGHT: rb_menu->setItemChecked( mRight, true );
113 break;
114 case TAB_DEC_PNT: rb_menu->setItemChecked( mDecPoint, true );
115 break;
116 }
117
118 rb_menu->popup( pnt );
119 } break;
120 default: break;
121 }
122}
123
124/*================================================================*/
125void KoTabChooser::drawContents( TQPainter *painter )
126{
127 if ( currType == 0 ) return;
128
129 painter->setPen( TQPen( black, 2, SolidLine ) );
130
131 switch ( currType ) {
132 case TAB_LEFT: {
133 painter->drawLine( 4, height() - 4, width() - 4, height() - 4 );
134 painter->drawLine( 5, 4, 5, height() - 4 );
135 } break;
136 case TAB_CENTER: {
137 painter->drawLine( 4, height() - 4, width() - 4, height() - 4 );
138 painter->drawLine( width() / 2, 4, width() / 2, height() - 4 );
139 } break;
140 case TAB_RIGHT: {
141 painter->drawLine( 4, height() - 4, width() - 4, height() - 4 );
142 painter->drawLine( width() - 5, 4, width() - 5, height() - 4 );
143 } break;
144 case TAB_DEC_PNT: {
145 painter->drawLine( 4, height() - 4, width() - 4, height() - 4 );
146 painter->drawLine( width() / 2, 4, width() / 2, height() - 4 );
147 painter->fillRect( width() / 2 + 2, height() - 9, 3, 3, black );
148 } break;
149 default: break;
150 }
151}
152
153/*================================================================*/
154void KoTabChooser::setupMenu()
155{
156 rb_menu = new TQPopupMenu();
157 TQ_CHECK_PTR( rb_menu );
158 mLeft = rb_menu->insertItem( i18n( "Tabulator &Left" ), this, TQ_SLOT( rbLeft() ) );
159 mCenter = rb_menu->insertItem( i18n( "Tabulator &Center" ), this, TQ_SLOT( rbCenter() ) );
160 mRight = rb_menu->insertItem( i18n( "Tabulator &Right" ), this, TQ_SLOT( rbRight() ) );
161 mDecPoint = rb_menu->insertItem( i18n( "Tabulator &Decimal Point" ), this, TQ_SLOT( rbDecPoint() ) );
162 rb_menu->setCheckable( false );
163}
164
165KoTabChooser::~KoTabChooser() {
166 delete rb_menu;
167 delete d;
168}
169
170void KoTabChooser::setReadWrite(bool _readWrite)
171{
172 d->m_bReadWrite=_readWrite;
173}
174
175#include <KoTabChooser.moc>